.htaccess file
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /project/
RewriteRule ^(\w+)/(\w+)/?$ index.php?pg=$1&id=$2 [L,QSA]
RewriteRule ^(\w+)/?$ index.php?pg=$1 [L,QSA]
RewriteRule . index.php?pg=home [L,QSA]
</IfModule>
tell me internal server error how to solve this problem.help me.
Add another one, on top of all others:
RewriteRule ^index\.php - [L]
It will end the redirects loop once index.php is "found"
Most likely reason of 500 is infinite looping. Add this rule just below RewriteBase /project/ to prevent rewriting for files and directories.
# skip all files and directories from rewrite rules below
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
Related
I have tried below code to redirect non www to www url in wordpresss but its not working .
Please check below code is right one?
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain.ie[nc]
RewriteRule ^(.*)$ http://www.domain.ie/$1 [r=301,nc]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
The proper .htaccess rule should be:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^yourdomain.com [NC]
RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [L,R=301]
Keep in mind that Wordpress has own rewrite rules installed in .htaccess file, do not remove them (they are placed between comments lines # BEGIN WordPress and # END WordPress)
According to the manual at https://www.ostraining.com/blog/wordpress/non-www/
The correct code is
RewriteCond %{HTTP_HOST} ^yourdomain.com [NC]
RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [L,R=301]
Otherwise there may be a other problem that you can reprocedure from the error logs
I am trying to redirect visits to https://www.domain.co.uk to http://www.domain.co.uk. I have researched this, but have come to a dead end.
Many people including people here, on SO suggest to use:
RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
This is my entire .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
I have tried putting the https rewrite code above, below and within the <IfModule mod_rewrite.c>. But had no luck.
I know the .htaccess is being read, as I can make it return a 500 internal server error when using random letters.
Thanks for your help.
EDIT
Anubhava found out my server isn't listening for port 443 as my VirtualHost has no entry for it.
Here's that section of my httpd.conf
If it is WP then in your permalink settings change your site's URL to http://domain.com which seems to be https://domain.com at present. WP forces that URL if you're using a different one.
Your full .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} on
RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
I need to redirect my dynamic URLs with parameters to subfolder URLs.
The source URL can vary in length/levels.
An example would be:
Source:
http://www.example.com/dir/?lang=en
Desired:
http://www.example.com/dir/en
and another would be:
Source:
http://www.example.com/dir/subdir/?lang=en
Desired:
http://www.example.com/dir/subdir/en
I'm using WordPress, so there is some existing code in my .htaccess, which the redirect in question, needs to work with. My existing .htaccess looks like this:
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [L]
I tried searching the entire web, however, no solution/answer seems to fit this particular case.
Any experts who can help?
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} !^lang=.+ [NC]
RewriteRule ^(.+?)/([^/]+)/?$ $1/?lang=$2 [L,QSA]
I'm having a problem with my mod rewrite rule that I wrote for my website, nothing seems to change as my pages URL are loading the same as before, if anyone could have a look at it and let me know if there is any problems it would be very much appreciated, thanks!
REWRITE RULE
RewriteEngine On
RewriteRule ^([^/]*)/$ /index.php?art_id=$1 [L]
URL
http://www.test.com/index.php?art_slug=test
DESIRED RESULT
http://www.test.com/test
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
# to externally redirect from /index.php?art_slug=test to /art_slug/test
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+/(?:index\.php|)\?([^=]+)=([^\s]+) [NC]
RewriteRule ^ /%1/%2? [R=302,L]
# to internally forward from /art_slug/test to /index.php?art_slug=test
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^([^/]+)/(.+)$ /index.php?$1=$2 [L,QSA]
Once you verify it is working fine, replace R=302 to R=301. Avoid using R=301 (Permanent Redirect) while testing your mod_rewrite rules.
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)$ index.php?art_id=$1 [L]
Should work. :)
RewriteEngine On
RewriteRule (.*)/$ search.php?keyword=$1
Should work. :)
Ok so I have this .htaccess file and it fetches the first dir after base as $1 and the second as $2
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 ^[^\.]+[^/]$
RewriteRule (.*) http://%{HTTP_HOST}/$1/ [R=301,L]
RewriteRule ^([^/]+)/([^/]+)/$ index.php?sub=$1&page=$2 [L]
RewriteRule ^([^/]+)/$ index.php?sub=$1&page=$1 [L]
#RewriteRule ^(.*)/(.*)$ index.php?sub=$1&page=$2 [L]
#RewriteRule ^(.*)$ index.php?sub=$1&page=$1 [L]
</IfModule>
Now we need to test this website on the productionserver in a subdirectory. This would add an additional directory to url
so:
hxxp://localhost/newwebsite/var1/var2/
Is there a way to only fetch the last two parameters of an url or should I just thrust it is going to work the way we want it. (not really an option)
Thanks!
Put the htaccess file in the newwebsite directory and change the RewriteBase / to RewriteBase /newwebsite/.