to clean and short the using .htaccess - .htaccess

I know many user have asked this question but i have tried everything still not understand the problem
I have url like this
http://localhost/test/storelocator.php?page=store
Now i want to like this
http://localhost/spawake/storelocator
My htaccess
# Turn Rewrite Engine On
RewriteEngine on
# Rewrite for storelocator.php
RewriteRule ^storelocator storelocator.php [NC, L]
but showing me the error in all the pages Internal Server Error So anyone can plz hep

Remove space after NC
Disable MultiViews option
Restrict your pattern by using end anchor.
Your .htaccess:
Option -MultiViews
RewriteEngine on
RewriteBase /spawake/fbdemo/
# Rewrite for storelocator.php
RewriteRule ^storelocator/?$ storelocator.php [NC,L]

Related

mod_rewrite strange infinite recursions

Server is Apache 2.4.18, PHP ver 7.0...
Intro:
On php side I rawurlencode($name) when creating html link.
REQUEST_URI looks like this:
/lang/cat1/cat2/product with bla (this/that) -- works
/lang/cat1/cat2/product with bla (this/ that) -- infinite internal redirect
The difference is only in one space this/ that vs. this/that
VirtualHost:
# I have tried different combinations of
AllowEncodedSlashes On
AllowEncodedSlashes NoDecode.
htaccess:
<IfModule mod_rewrite.c>
Options +FollowSymLinks -MultiViews #different combinations
RewriteEngine On
# tried different combinations
#RewriteCond %{REQUEST_URI} !^/?file\.php$
#RewriteCond %{ENV:REDIRECT_STATUS} ^$
#RewriteCond %{ENV:REDIRECT_STATUS} !200
RewriteRule .? file.php [L] # END
</IfModule>
All I want is standard front controller, ALL requests should go to file.php That works in 99.99% of cases. But ruri with bla/ in it goes to infinite recursions.
Questions:
Why is this happening?
How to solve it?
You need to uncomment your last rewrite condition.
Try :
<IfModule mod_rewrite.c>
Options +FollowSymLinks -MultiViews #different combinations
RewriteEngine On
# tried different combinations
#RewriteCond %{REQUEST_URI} !^/?file\.php$
#RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{ENV:REDIRECT_STATUS} !200
# END
</IfModule>
Otherwise your rule will redirect /file.php to itself.
On apache 2.4 you can simply use END flag to terminate the rewrite processing :
RewriteEngine on
RewriteRule .? file.php [END]
I have found a solution on another forum.
Solution was painfully simple. But might help someone.
One guy sad: Be brave, understand that there is nothing wrong with your htaccess! But you still have recursions. So bug is somewhere in php code.
That destroyed my htaccess fixation allowing me to dive into business and fw code. Bug was found few hours later. One of url functions had premature rawurldecode(). Cool for lazy programin, not so cool if you have products with encoded / in names.
But the answer to question "Did this work before?" was misleading also. "Yes, sure. It must be because of resent migration."
Riiight ;)

htacces rewrite single file

I want to rewrite a specific file on my website to another one by using htaccess:
# General
RewriteEngine On
RewriteBase /
Options All -Indexes
Options +FollowSymLinks
# Rewrite file
RewriteRule ^/file.html$ /dir/file.html [L]
This is the .htaccess code i'm using based on snippets i found on the internet.
Somehow this is not working, the server is returning a 404-Not-found error.
I can't see any difference with example's that are said to work, like in
Rewriting path for a specific file using htaccess
Edit:
If I place file.html in the root-folder, I can view it. So the rewrite definitely is not happening.
RewriteRule does not receive leading slash. Write so:
RewriteRule ^file.html$ /dir/file.html [L]

Using .htaccess and mod_rewrite

I'm having some mod_rewrite problems with my .htaccess..
RewriteBase /folder
RewriteEngine on
Rewrit­eRule ^(.*)$ basic.p­hp?­url=$1 [L]
Above is what I'm currently using. However, I have no idea what I'm doing to be honest as I'm just cycling through the internet trying to figure this out.
Basically, for my website, if you type in
www.domain.com/folder/xxx/
I want it to basically be www.domain.com/folder/basic.php?url=xxx.
For some reason, all that does is cause a 404 error :/
So can someone please politely point me in the right direction?
Ok, I will explain using your htaccess.
RewriteEngine on
Turn on the Rewrite Module to enable URL rewriting
RewriteBase /folder
Rewrite the Base Directory to directory name folder
RewriteRule ^folder/(.*)$ basic.php?url=$1 [L]
Remap every request make using the folder/***** to basic.php?url=********
Note: RewriteEngine On Should be the first statement on your case
RewriteEngine on
RewriteBase /
RewriteRule ^folder/(.*)$ folder/basic.php?url=$1 [L]
This is more of a problem with regexs than .htaccess files.
http://httpd.apache.org/docs/current/mod/mod_rewrite.html
http://www.regular-expressions.info/

.htaccess mask - SEO

Looking to put the following into my htaccess file:
User visits http://mysite.com/test/test/123
User is actually visiting http://mysite.com/test/index.php?q=123
I have seen it done before but I can't figure it out. The user is not supposed to see that they are visiting the second url. This is particularly useful for SEO. Can anyone help me on this one?
Updated Code for Answer:
Options -Multiviews
rewriterule ^test\/([a-zA-Z]+)\/([0-9]+)$ test\/index\.php?id=$3 [L]
*Note: The Options -Multiviews is needed for GoDaddy hosting to enable mod_rewrite.*
Be sure mod_rewrite is on:
RewriteEngine on
RewriteRule ^test/([a-zA-Z0-9_-]+)/([0-9]+)\.html$ test.php?id=$2
Double test
RewriteEngine On
RewriteRule ^test/test/([^/]*)$ /test/index.php?q=$1 [L]
Single test
RewriteEngine On
RewriteRule ^test/([^/]*)$ /test/index.php?q=$1 [L]

URL rewrite using mod_rewrite in .htaccess

I am trying to rewrite the URL using the mod_rewrite apache module.
I am trying to use it as below :
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
RewriteRule ^wants/testing.htm wants.php?wantid=$1 [L]
I have created a .htaccess file in the directory from where the files are accessed.
The mod_rewrite is also enabled.
With all these done, i still haven't been able to get it working.
Can someone please help me with this? Please let me know if i am missing something
Thanks in Advance,
Gnanesh
As per OP's comment:
The URL shows
mydomain.com/wants.php?wantid=123. I
need to make it look like
mydomain.com/wants/123
This should work for your case:
RewriteEngine on
RewriteBase /
RewriteRule ^wants/([0-9]+)$ /wants.php?wantid=$1 [L]
It will allow you to use http://yoursite.com/wants/123 and will silently rewrite it to wants.php?wantid=123
I think a leading slash (or rather the lack thereof) might be yoru problem:
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
RewriteRule ^wants/testing.htm /wants.php?wantid=$1 [L]
Otherwise Apache might be looking for the PHP file in /wants/wants.php as it'll be treating it as a relative URL.
Hmm, so I gave it some thought and I guess you could do something like this ( only changed the regexp according to your comment, if I understood correctly ):
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
RewriteRule ^wants/\d+$ /wants.php?wantid=$1 [L]
But I guess you could also leave out the $1 reference, and still be able to access the id in your wants.php. So
RewriteRule ^wants/\d+$ /wants.php [L]
should work too, and you can then use something like
<?php
$request = split('/', $_SERVER["REQUEST_URI"])[1];
?>
in your wants.php where the last element of the array would be your id ( or anything else you ever decide to rewrite and send to the script ).
If you want to use the rule in the .htaccess file in your wants directory, you have to strip the contextual wants/ from the start of the pattern. So just:
RewriteEngine on
RewriteRule ^([0-9]+)$ /wants.php?wantid=$1 [L]
Otherwise, if you want to use the rule in the .htaccess file in your root directory:
RewriteEngine on
RewriteRule ^wants/([0-9]+)$ wants.php?wantid=$1 [L]

Resources