Getting Error 500 when trying to use RewriteRule - .htaccess

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.

Related

htaccess Rewrite Error, Can not fetch $_GET value PHP :(

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

Mod_Rewrite with .htaccess is not working

I just learnt about url-rewrite for my website with .htacess. My actual url is:
localhost/index.php?view=some-page
So i write this RewriteRule like this:
RewriteRule ^/([^/]*)/?$ /index.php?view=$1 [NC,L]
When i typed localhost/homepage on my browser, It does not work, it displays error 404 object not found. What have i done wrong please show me.
Many thanks
This should work in your DocumentRoot/.htaccess:
RewriteEngine On
RewriteBase /
RewriteRule ^([^/]+)/?$ index.php?view=$1 [QSA,L]
Leading slash is not matched in htaccess.
are you using apache?
This link from step 6 helped me
https://www.digitalocean.com/community/tutorials/how-to-install-wordpress-on-ubuntu-14-04
When i was playing around with rewrites i had to enable it and tell apache where the pages were stored

.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.

.htaccess RewriteRule giving 500 server error

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.

Question about a redirect

I just noticed that sometimes (even when given a wrong url) load perfectly fine. How do they accomplish this? What I mean is, suppose you click on a link that seems good like www.foo.com but it contains in the end a space character which would appear on the address bar as www.foo.com%20 some sites manage to redirect this to their correct url while others just break. How can this be achieved? I'm guessing it's something to do with the .htaccess but I have no idea what to do or where to do it.
The URL I'd like to redirect looks like this actually: http://foo.com/%C2%A0
I get the following error message:
The requested URL /%C2%A0 was not found on this server.
How can I make this redirection?
So far I came up with:
RewriteEngine on
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /[^%?\ ]*\%
RewriteCond %{REQUEST_URI} !^/
RewriteRule ^(.*)$ http://www.foo.com/ [R=301,L]
but it's not working at all

Resources