.htaccess Rewrite rule doesn't work - .htaccess

I know there are already a ton of these questions but I don't get it...
I'm trying to rewrite my /register.php to /register but I can't.
.htaccess code
RewriteEngine on
RewriteBase /
RewriteRule ^register$ register.php [L]
Does any of you know the answer?
Sorry for the stupid question but I'm kinda new to the whole .htaccess stuff...

Do you have enabled the Apache module mod_rewrite?
I use this pattern to create user-friendly URLs. It's pretty variable. It means, that every address in format letters-numbers with a certain file extension (PHP or HTML) will be translate into letters-numbers.php (for example).
RewriteRule ^([a-z]+)-([0-9]+)\.(php|html)$ /$1-$2.$3 [L]

Related

htaccess is working but does not replace the url

I'm trying to modify the subdomain name in the URL to make it look nicer. My current URL look something like:
www.mystore.com/productInfo.php?cPath=11_11&productID=222
So, I want to make it nicer by Rewrite in .htaccess in main with this code:
RewriteEngine On
RewriteRule ^productInfo/([0-9_-]+)/([0-9_-]+) productInfo.php?cPath=$1&productID=$2 [NC,L]
When I run and test it on the URL by typing www.mystore.com/productInfo/11_11/222 in the URL it works well. However, when this page is redirected by a different page or is 'refreshed' with a self redirecting a href= link(in which the link is written in php by the previous programmer), the above old link is still visible in the URL instead of the new one.
I am still a beginner while I suspect that I might need to change something in the cPanel/Apache(I think) for this but currently, I am still do not have access to the cPanel control. Is there anything that I might have missed to write in the .htaccess file or I really do need the cPanel control or any other reasons?
Any help is appreciated. Sorry that I could not find similar questions on this.
You can use the following :
RewriteEngine On
RewriteBase /
#redirect /productInfo.php?cPath=foo&productID=bar to /productInfo/foo/bar
RewriteCond %{THE_REQUEST} /productInfo\.php\?cPath=([0-9_-]+)&productID=([0-9_-]) [NC]
RewriteRule ^ productInfo/%1/%2? [L,R=301]
#rewrite new URL to the old one
RewriteRule ^productInfo/([0-9_-]+)/([0-9_-]+) productInfo.php?cPath=$1&productID=$2 [NC,L]

.htaccess url rewrite rule to subdirectory not working

I want this: RewriteRule ^paper$ /express/index.php?c=p [L] but it does not work. Instead, it's trying to send me to /index.php?c=p, ignoring the subdirectory express altogether. However, RewriteRule ^express/paper$ /express/index.php?c=p [L] works. This is my .htaccess code:
RewriteEngine on
RewriteBase /
RewriteRule ^paper$ /express/index.php?c=p [L]
RewriteRule ^express/paper$ /express/index.php?c=p [L]
The url I WANT is just http://site.com/paper but I have to do http://site.com/express/paper to get the rewrite rule to work.
And yes, I only use one of those rewrite rules at a time.
UPDATE
Well, I'm not really getting any responses, so I'm going to go ahead and close this browser tab. I'll check back now and then but don't be offended if it takes a little while. Thanks for any help offered.

How to remove middle part from URL - mod_rewrite

How to rewrite this url "www.domain.com/index.php?route=custom/static/page" to "www.domain.com/page" in htaccess file, basically just want to take out index.php?route=custom/static/ from urls.
I don't know regex so I tried http://www.generateit.net/mod-rewrite/, but it only generates
RewriteEngine On
RewriteRule ^([^/]*)$ /index.php?route=$1 [L]
which doesnt remove 'custom/static' from URLs, I tried a few other examples as well but only removes index.php? and doesnt pass variable, any help is appreciated.
Do you know the concept of using mod-rewrite?
In your question you have mentioned to use mod-rewrite to redirect
"www.domain.com/index.php?route=custom/static/page",
Here $_Get['route']="custom/static/page"] $url_parameter=$_Get['route']
to
"www.domain.com/page" [here $_Get['route']="page"],
So now you can mannually add "custom/static/" to the obtained value of $_Get['route']. as $url_parameter="custom/static"+$_Get['route'] //For PHP
Using your mod_rewrite you can fulfill your demands,
RewriteEngine On
RewriteRule ^([^/]*)$ /index.php?route=$1 [L]
But if you need out of box solution using .htaccess then I suggest learning "rewrite-engine" instead of using generating tool

mask URL (with parameters) with htaccess

i need to mask a long, stupid php URL with a relatively simple URL with htaccess.
For example, i need to mask -
http://mysite.com/index.php?this=that&this=that&whatevs=this&that=&id=5
with this simple URL -
http://mysite.com/mypage.php
I know php can do the stuff very easily by fetching the content of that page and displaying it. But in my conditions, there are some problems with ajax calls and some other things.
Moreover, i prefer to use htaccess. I did some research but htaccess codes are very confusing to me.
I took the liberty of removing the .php part from mypage.php as it has no real use, and makes the url look less pretty.
RewriteEngine On
RewriteBase /
RewriteRule ^mypage$ /index.php?this=that&this=that&whatevs=this&that=&id=5 [L,QSA]
So you only want redirect http://mysite.com/index.php?this=that&this=that&whatevs=this&that=&id=5 to http://mysite.com/mypage.php?
Then use this RewriteRule:
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} this=that&this=that&whatevs=this&that=&id=5
RewriteRule ^index.php$ http://mysite.com/mypage.php? [L,R=301]

Rewrite basic $_GET variable to friendly URL using mod_rewrite

I know questions similar to this are common. I just don't even know where to begin with rewrite rules with the /'s and .'s I don't know how to retrofit other peoples solutions to mine. Onto my situation:
I am using a basic get on the index.php file that looks like
http://www.example.com/index.php?page=about
I want to rewrite that to
http://www.example.com/about
I know this is fairly simple rewrite wise, but its just a totally different language which I have tried and failed to comprehend. Thanks
Try this:
RewriteEngine on
RewriteRule ^([^/\.]+)/?$ /index.php?page=$1 [L]
Or even:
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(?!index.php\b).* index.php?page=$0 [L,QSA]
Note:
You should always set the RewriteBase in an .htaccess file.
I've generalised this so that index.php picks up any string which isn't mapping to a real file
The (?!index.php\b) is a regexp which says "but don't match to index.php"
You will need the [QSA] flag if your requests can contain request parameters. This merges them.

Resources