user friendly URL rewrite rule - .htaccess

Could anyone advise on how to I can rewrite this url:
https://test.com/user/user.php?u=name
to
https://test.com/user/user/name
Please?
Below is my rewrite rule but it's not doing exactly what I want.
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)/user/([^/]+) /user.php?u=$1 [L]
Thanks a lot

Try this:
RewriteEngine On
RewriteRule ^user/user/([^/]*)/?$ /user/user.php?u=$1 [L]

Related

.htaccess rewrite rule with get params

I need to be able to rewrite http://example.com/staging/details/?postid=23 so that it becomes http://example.com/staging/grandhotelterduin
I am not sure how the .htaccess rule should be?
I have came up with something like this
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^grandhotelterduin/(.*)$ ./details/?postid=23 [L,NC]
I am not sure I am doing this correctly, can you plz help
I want it such that the http://example.com/staging/grandhotelterduin/ get redirected to http://example.com/staging/details/?postid=23 but the url that appears in the browser is `http://example.com/staging/grandhotelterduin
Use this:
RewriteEngine On
RewriteRule ^grandhotelterduin$ /staging/details/?postid=23 [L]
It will give you the following URL:
http://sheetz.nl/grandhotelterduin
EDIT:
RewriteCond %{THE_REQUEST} /staging/details/?postid=([0-9]+) [NC]
RewriteRule ^ /staging/grandhotelterduin [L,R]

Joomla Custom URL through htaccess

My URL: https://domain.com/my-team-league/viewgroup/201-crick
Needed URL: https://domain.com/league/201-crick
Help me to take out of this url issue please
.htaccess:
DirectoryIndex index.php
RewriteEngine On
RewriteBase /
RewriteRule ^/league/(.+) /my-team-league/viewgroup/$1
Use the opposite (and without /):
RewriteEngine on
RewriteRule ^my-team-league/viewgroup/(.+) league/$1 [R=302,L]
Try with [R=302,L] and after, when that work well, change for [R=301,L]

Rewrite rule in .htaccess and redirect

i would like the url being rewritten automatically from :
hello.com/a-b-c/0/
to:
hello.com/a-b-c/1/
I have a rewrite rule on .htaccess
RewriteRule ([a-zA-Z0-9\.\-]+)/0/?$ $1/1/ [NC,L]
But that doesn't seem to work. may I know what is the issue?
Thanks.
You can try this rule for redirect:
RewriteRule ^([a-zA-Z0-9.-]+)/0/?$ /$1/1/ [R,L]
Or for internal rewrite:
RewriteRule ^([a-zA-Z0-9.-]+)/0/?$ /$1/1/ [L]

mod_rewrite 301 redirect not working

I'm trying to set up a rewrite that will redirect this URL:
/video-2011.php?video=150
to this:
/video/150/freeform-title-text-here/
I have the rewrite working using this line in my HTACCESS:
RewriteRule ^video/([0-9]+)/(.*)$ video-2011.php?video=$1 [L]
But as soon I add R=301 into the mix, it breaks. Any ideas?
Here's the full HTACCESS when it breaks:
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteRule ^video/([0-9]+)/(.*)$ video-2011.php?video=$1 [R=301,L]
Any help is greatly appreciated, thanks!
I think you might be missing a line from your .Htaccess.
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteRule ^video/([0-9]+)/([a-z0-9-_]+)$ video-2011.php?video=$1 [L]
#New
RewriteCond %{REQUEST_URI} !^/video/([0-9]+)/([a-z0-9-_]+)/?$
RewriteCond %{QUERY_STRING} ^video=([0-9]+)&name=([a-z0-9-_]+)/?$
RewriteRule ^video-2011.php$ video/%1/%2/? [R=301,L]
I assuming you want to rewrite the url if it is:
/video/150/freeform-title-text-here/
And redirect the url if it is:
/video-2011.php?video=150
to:
/video/150/freeform-title-text-here/
So this way it keeps the urls looking pretty and tidy.
Please correct me if I am wrong.
Edit
I've added in a RewriteCond to stop the second rewrite happening.
As the first rule will obviously rewrite:
/video/150/freeform-title-text-here/
Which means the query string you don't see:
/video-2011.php?video=150
Would of made the second rule happen too.
Can you try:
RewriteRule ^video/([0-9]+)/ /video-2011.php?video=$1 [R=301,L,NC,QSA]
And yes it will redirect /video/150/foo to /video.php?video=150 not the other way around as you've stated in your question.

URL rewriting using htaccess

How to rewrite the url in htaccess
www.mywebsite.com/category.php?name="richard" change to www.mywebsite.com/richard/
You can use below code to achieve your requirement.
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{QUERY_STRING} name=(.*)
RewriteRule category\.php$ /%1/
Hope this helps you... :)
Are you used any PHP frameworks(like the codenigter... etc)?
You can try this:
RewriteRule ^(.*)$ /category.php/name=$1 [L]

Resources