I have a site running on pynton django and I am trying to keep accessible some urls of it, while having a index.html showing.
I've tried to rewrite my .htaccess file but without results. Can anyone help?
Here is my code:
AddHandler fcgid-script .fcgi
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>
RewriteRule ^music/preview/listen$/(.*)$ http://example.org/music/preview/listen/$1 [L,R=301]
thanks a lot.
You've got some issues with syntax, it looks like some of your newlines are missing and you have a malformed regex at the end. Try cleaning it up:
AddHandler fcgid-script .fcgi
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !example\.org$ [NC]
RewriteRule ^music/preview/listen/(.*)$ http://example.org/music/preview/listen/$1 [L,R=301]
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>
Note that the ^music/preview/listen$/(.*)$ isn't valid, you can't have two $ "end of string" characters.
Related
I'm trying to alter my htaccess file to redirect, but it's not working and I'm not sure why. The old urls are now giving 404s if that's important.
Old structure: https://www.example.com/category/tag/id/slug
New structure: https://www.example.com/article/slug
I want to capture the slug and put it in the new structure. My htaccess file looks like this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteRule ^/.*/.*/.*/(.*)$ /article/%1 [R=301,NC,L]
</IfModule>
I was thinking I had the last RewriteRule correct there, but perhaps I'm missing something?
Solved.
Correct syntax was:
RewriteRule ^.*/.*/.*/(.*) /article/$1 [R=301,NC,L]
I'm trying to create an htaccess file so that everything gets redirected to the root of the site except for an specific path /api/date.
I have this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
I've made some research on javascript regex and it seems that it is not possible to exclude words. So it is possible to do this here? How?
Thanks!
Try with below we are excluding /api/date and passing everything apart from that.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(?!(\/api\/date)$).+$ /index.php [L]
</IfModule>
The problem: the presence of an identical URL to /page/, but with some file extension, i.e., /page.xml, results in a 404 for /page/.
So for example, my HTML sitemap, example.com/sitemap will 404 if example.com/sitemap.xml is present.
The .htaccess file of my Wordpress site contains rewrite conditionals that, as expected, appends a trailing slash to pages in the form of example.com/page so they are rewritten as example.com/page/.
.htaccess as follows:
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule .* https://example.com%{REQUEST_URI} [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)([^/])$ /$1$2/ [L,R=301]
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
# BEGIN MainWP
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^wp-content/plugins/mainwp-child/(.*)$ /wp-content/plugins/THIS_PLUGIN_DOES_NOT_EXIST [QSA,L]
</IfModule>
# END MainWP
So after some digging, I found the solution, which was to simply disable Multiviews in my .htaccess file, like so:
Options -MultiViews
I have a wordpress site set up with some custom redirect rules set up. The weird thing is I am sure these all of these were working before but now some of them no longer function.
Here is the complete htaccess file:
RewriteRule ^properties/([a-zA-Z]+)/([a-zA-Z\+\'.]+) /properties/?prov=$1&city=$2&%{QUERY_STRING} [R,NC]
RewriteRule ^properties/([0-9]+) /properties/?id=$1 [R,NC]
RewriteRule ^([0-9][0-9][0-9][0-9][0-9])$ /properties/?id=$1 [R,NC]
RewriteRule ^expand.php?id=([0-9]+) /properties/?id=$1 [R,NC]
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wordpress/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wordpress/index.php [L]
</IfModule>
# END WordPress
right now the only rule that actually works (other than the directory change for wordpress itself) is
RewriteRule ^([0-9][0-9][0-9][0-9][0-9])$ /properties/?id=$1 [R,NC]
I've tried throwing in simple rules to test, like
RewriteRule ^/bob /contact [R,NC]
but that doesn't work either
* Edit the below issue was fixed and is definitely not related to the issue above (but I'll leave it here in case there was a comment that referenced it)*
Also, not sure if this gives any insight but on the page where the redirect actually works, my wordpress theme is broken, the wp_footer never fires and the rest of the page fails
Have it like this:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wordpress/
RewriteRule ^bob/?$ /about [R,NC,L]
RewriteRule ^properties/([a-zA-Z]+)/([a-zA-Z+'.]+)/?$ /properties/?prov=$1&city=$2 [R,NC,QSA,L]
RewriteRule ^(?:properties/)?([0-9]+)/?$ /properties/?id=$1 [R,QSA,NC,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wordpress/index.php [L]
There are a couple of possible causes... You aren't enabling mod_rewrite until after your RewriteRules, the custom rules should be included inside their own <IfModule mod_rewrite.c> tag with RewriteEngine on preceding them, and you probably want to set RewriteBase to whatever the root of your site is (perhaps /wordpress subdirectory? you may want to include what you would like these rules to rewrite to and from.) You cannot match on a querystring within a RewriteRule either, you have to use a RewriteCond.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^properties/([a-zA-Z]+)/([a-zA-Z\+\'.]+) /properties/?prov=$1&city=$2&%{QUERY_STRING} [R,NC]
RewriteRule ^properties/([0-9]+) /properties/?id=$1 [R,NC]
RewriteRule ^([0-9]{5,5})$ /properties/?id=$1 [R,NC]
</IfModule>
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wordpress/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wordpress/index.php [L]
</IfModule>
# END WordPress
Also updated ^([0-9][0-9][0-9][0-9][0-9])$ to the form ^([0-9]{5,5})$ which is a bit more readable.
Your example/test should look like the following - omit the / because it is set in the RewriteBase.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^bob /about [R,NC]
</IfModule>
I changed my permalinks and it working fine, but I need to redirect old tag folder to archives/tag to not lose links which google indexed
below is my .htaccess file in the root of my recipes site http://foodonia.com
# Use PHP5.4 as default
AddHandler application/x-httpd-php54 .php
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Example: http://foodonia.com/tag/fudge/ should redirect to http://foodonia.com/archives/tag/fudge
I tried to add each one of blow codes but redirect not working
#RewriteRule tag/(.*) archives/tag/$1 [NC,L]
#RewriteRule tag/$ /archives/tag/$1 [NC,L]
#RewriteRule tag/ /archives/tag [L]
even I tried redirect 301 ^/tag/fudge/ http://foodonia.com/archives/tag/fudge/ but it didn't work
I try to search for solution but can't find similar post
You need to use rules in correct order i.e. to use this 301 first before other WP rules.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule (tag/.*)$ /archives/$1 [NC,NE,L,R=301]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>