how do I create a url rewrite in htaccess - .htaccess

I have a link: admin/tcpdf/examples/viewContract.inc.php?id=MTE4 and am trying to make a rewrite rule to just: /contract/
Would love some assistance with this!

This should do the trick
RewriteEngine On
RewriteRule ^/?admin/tcpdf/examples/viewContract.inc.php*$ /contact/ [R=301,L]
How to handle 404
RewriteRule ^/?error404\.php$ - [R=404]

Related

user friendly URL rewrite rule

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]

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]

How to rewrite /?custom_ref= with /?ref= using htaccess rewrite

How to rewrite
/?custom_ref=
with
/?ref=
using htaccess rewrite???
RewriteEngine On
RewriteCond %{QUERY_STRING} custom_ref=(.*)
RewriteRule (.*) /?ref=%1 [R=301,L]
Can you please tell me the directory/file that you using this query on so I make sure this code will only work with it.

htaccess 301 Redirect issue

I have the following URL structures for my website:
http://domain.com/slug/1/test-test.html
http://domain.com/slug/2/test-test.html
and i want to change it to
http://domain.com/new-1-test-test.html
http://domain.com/new-2-test-test.html
i have already tried
RewriteRule ^slug$ /new- [R=301,L]
RewriteRule ^/?my\slug /new [R=301,L]
but it does't work..
anyone know how to redirect this with htaccess?
Thanks
Try this - RewriteRule ^slug/([0-9]+)/(.*)$ /new-$1-$2 [R=301, L]
RewriteEngine On
RewriteRule ^slug/([0-9])/(.*)$ /new-$1-$2 [R-301,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.

Resources