I have a rewrite rule as follows:
RewriteRule ^equipment /equipment.php [L]
It will throw a 500 server error... but if I were to replace the equipment.php with, for example, our contact page contactUs.php it will redirect to the contact page with no problems.
I have other rewrite rules that work fine - but I can't figure out why this won't work.
Limit your Rule by adding $
RewriteRule ^equipment$ /equipment.php [L]
I found the answer.
I needed to do RewriteRule ^equipment/$ /equipment.php [L]
Thanks all.
Related
I am sorry to open a replicated question once again but I had no other choice. I am trying to write a clean URL using .htaccess. Here is my code:
RewriteRule ^home index.php [NC,L]
RewriteRule ^about-us about-us.php [NC,L]
RewriteRule ^careers careers.php [NC,L]
RewriteRule ^contact-us contact-us.php [NC,L]
these works very finely. but when I move on to URL's having some GET params like
example.com/providers.php?provider=huawei
and the htaccess rule goes as:
RewriteRule ^providers/([a-zA-Z_-]+) providers.php?provider=$1 [NC,L]
When I navigate to the URL example.com/providers/huawei it throws an error
Notice: Undefined index: provider in directory\providers.php on line x
Appearantly, there is no error in the rule, I have gone through several video and StackOverflow solutions. Some suggested the use of QSA but no luck. I changed my production servers too still negative. Any help in this regard.
TIA
I'd like to create some kind of redirection script using .htaccess to map short urls (like example.com/1 to other urls). To do so, I've created this:
RedirectPermanent /1 https://www.youtube.com/watch?v=...
RedirectPermanent /2 https://www.youtube.com/watch?v=...
So far, that's working. However, it's missing a fallback. I'd like to add a 404 page that is shown whenever someone tries to navigate a URL that doesn't have any redirect (yet).
I've tried adding this:
...
RewriteCond %{REQUEST_URI} !^/404.html$
RewriteRule .* /404.html [L,R=302]
Obviously, this isn't working, because now ALL calls are redirected to 404.html. I thought about adding the redirects as conditions, but since there might be many redirects that approach seems very bad to me.
What can I do instead?
Thanks for helping out.
I've done this now, but I'm not sure if this is the best solution.
Please comment if you have any advices.
RewriteRule ^/1$ https://www.youtube.com/watch?v=1 [L,R=301]
RewriteRule ^/2$ https://www.youtube.com/watch?v=2 [L,R=301]
RewriteCond %{REQUEST_URI} !^/404.html$
RewriteRule .* /404.html [L,R=302]
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.
I am trying to figure out the code to make all my links with no extension to be redirected to a certain page using .htaccess. For example:
http://mysite.com/link
Gets rewritten to:
http://mysite.com/run.php?id=link
I have tried the following code but I receive an Internal Error 500 and can't even access my homepage.
RewriteEngine On
RewriteRule ^([^/]*)$ /run.php?id=$1 [L]
Thanks for your help I think found the answer:
RewriteEngine on
RewriteBase /
RewriteRule ^.htaccess$ - [F]
RewriteRule ^([A-z,0-9,_,-]+)/?$ /run.php?id=$1 [QSA]
This seems to work. Although I'm not soo sure if anything else is affected. The homepage still loads if I type www.mysite.com/index.php so I think it is ok.
The commented out google redirect is working but the rest of the rules dont work at all.
it automatically gives me a 500 internal server error. This only happens on the 1and1 server.
RewriteEngine On
Options FollowSymLinks
# RewriteRule ^(.*)$ http://www.google.com/$1 [r=301,nc]
RewriteRule ^(ajax)/([a-zA-Z0-9-z\-]+)$ http://mysite.com/index.php?ajax=$2 [r=301,nc]
RewriteRule ^([a-zA-Z0-9-z\-]+)/([a-zA-Z0-9-z\-]+)$ http://mysite.com/index.php?page=$1&subPage=$2
RewriteRule ^([a-zA-Z0-9-z\-]+)/([a-zA-Z0-9-z\-]+)/$ http://mysite.com/index.php?page=$1&subPage=$2
RewriteRule ^repairs/([a-zA-Z0-9-z\-]+)/([a-zA-Z0-9-z\-]*)$ http://mysite.com/repairs-engine.php?page=repairs&subPage=$1&pitem=$2
RewriteRule ^([a-zA-Z0-9-z\-]+)$ http://mysite.com/index.php?page=$1
RewriteRule ^([a-zA-Z0-9-z\-]+)/$ http://mysite.com/index.php?page=$1
Any thoughts?
Thanks
For exact error description you should check the Apache's error log.
What this pattern supposed to mean [a-zA-Z0-9-z\-] ?? It is definitely wrong. It should be [a-zA-Z0-9\-] -- I'm pretty sure that this is the reason for error.
NOTES:
If using [NC] flag, then no need to have a-zA-Z -- just a-z will be enough.
If doing rewrite (internal redirect, when URL changes in browser's address bar) and not proper redirect (301, 302 etc), then no need to use full domain name.
In any case, I suggest adding [L] flag to all rules -- it will speed up processing by tiny bit.
have you tried not to escape the last dash in the char class block?
like this:
^([a-zA-Z0-9-]+)$