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]
Related
I have a WordPress site running in an apache server, I want to rewrite some the URL in SEO friendly manner, so how to do that
Currently, I have this URL
www.example.com/about-us/?id=what_we_do_1
www.example.com/about-us/?id=why_us
I want it like
www.example.com/about-us/what-we-do-1
www.example.com/about-us/why-us
and for this
www.example.com/media/?id=team
www.example.com/media/?id=abc_xyz
I want something like this
www.example.com/media/team
www.example.com/media/abc-xyz
my current .htaccess is like the below
# 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
To convert urls like
/index.php?p=test
to
/index.php/test
RewriteEngine On
RewriteCond %{QUERY_STRING} p=(.+)
RewriteRule ^/?index.php$ /index.php/%1? [R,L]
Thus in your case
RewriteEngine On
RewriteCond %{QUERY_STRING} p=(.+)
RewriteRule ^/?about-us?$ /about-us/%1? [R,L]
Similarly for other pages
You can try these to convert underscore to dash :-
RewriteEngine On
RewriteBase /
After that for another url :-
1) www.example.com/about-us/?id=what_we_do_1
htaccess rule will be :-
RewriteRule ^about-us/(.*)$ about-us/?id=$1 [QSA,L]
It may help you.
.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]
I have a website and i want to make it always show as www.mysite .com i put that code in .htaccess :
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
</IfModule>
now the url shows as www but the website is not shown the browser said "This webpage has a redirect loop"
Note: .htcaccess do not have any code but this few lines i wrote
does i did anything wrong or i miss something??? please help
Edit:
before I add the above code the .htaccess had the following code but not direct to www i remove it :
# 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>
RewriteCond %{QUERY_STRING} ^m=1$
RewriteRule (.*) $1? [R=permanent]
# END WordPress
could that be updated to solve my problem?
if you are doing it at windows server it will not work if it is window you have to create web.config file n for linux it should be .htaccess
Ok so Wordpress is also there. Make sure to do these 2 things:
Put your 301 rule above WP's rules i.e. just below RewriteBase line
Update WP settings to have your site address with www
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [L,R=301]
or
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
i want to manage url of my website
right now its showing me www.computermall.co.in/product_details.php?prdid=34
but i want www.computermall.co.in/product_details/34
how can i do it?
i have tried this
Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /computermall
# Get the URI-path directly from THE_REQUEST variable
RewriteCond %{THE_REQUEST} ^(GET|HEAD)\s/(.*)\.php [NC]
# Strip the extension and redirect permanently
RewriteRule .* /%2 [R=301,L,NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !\.php [NC]
# Map internally to the original resource
RewriteRule ^(.*)$ $1.php [L,QSA]
Try this:
RewriteEngine On
RewriteRule ^product_details/prdid/([^/]*)$ /product_details?prdid=$1 [L]
Edit: removed leading slash
First of all your RewriteBase /computermall is confusing but i am assuming thats there because your domain is in a sub directory of another active domain/http server path.
Here is your htaccess
RewriteBase /
RewriteRule ^computermall/product_details/([^/]*)/([^/]*$ /computermall/product_details?prdid=$2 [R=301,L]
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. :)