I use this htaccess url
mywebsite.com/xyz/search.html
here xyz is a folder in root
in .htaccess is use the code for this url
# enable apache modRewrite module #
RewriteEngine On
RewriteBase /
RewriteRule ^([^//]+)/?(^/*)?.ht(m?ml?)$ index.php?page=$1 [L,QSA]
now i want this
xyz/search.html is hit the
url xyz/index.php?page=search
but this:
RewriteRule ^([^//]+)/?(^/*)?.ht(m?ml?)$ index.php?page=$1 [L,QSA])
code is not working..
any idea regarding this...
Type some random characters in your .htaccess file and try to reload your page, if you see error 500 then your .htaccess file is working, put your random characters after "RewriteEngine On" .
Not sure that rule would work. Does this one do the job?
RewriteRule ^.*/(.*)\.html?$ index.php?page=$1 [L,QSA]
Also, if you want to test the rule with a bit more visibility, you can add R=302 to the flags, that way your browser will get a redirect and you'll be able to see the rewritten URL in the address bar
I wonder why people don't use RewriteLog.
Put in the same place:
RewriteLog /tmp/rewrite.log
RewriteLogLevel 3
It slows down the server but for debugging it's made for.
Try:
RewriteEngine On
RewriteBase /
RewriteRule ^(.*?)/?([^/]+)\.ht(m|ml)?$ $1/index.php?page=$2 [L,QSA]
There is a very handy online tool for testing htaccess files. Simply paste your redicrect rules in the form provided and test various urls to see if they are redirected or left untouched.... soooper easy!
Related
Following is my rewrite rule code written in the .htaccess file placed in the
beta1
folder.
Options +FollowSymlinks
RewriteEngine on
RewriteBase /beta1/
RewriteRule /(.*) read.php?post=$1 [R,NC]
Currently the URL is:
http://localhost/beta1/read.php?post=Happy+Mother+Day.
And i want the link to appear like:
http://localhost/beta1/Happy-Mother-Day.
Do I also need to change the way "read.php" extracts data from the database? If yes, then how?
Do i also need to make any changes in the "read.php" file?
The rewrite code above is not working.
hey please try this rule
RewriteEngine On # Turn on the rewriting engine
RewriteRule ^([A-Za-z0-9-_]+)?$ read.php?post=$1 [NC,L]
And read.php file
echo str_replace('-',' ', $_GET['post']);
I want to be able to open the following url
http://example.com/login/12345
and in the background, it should load:
http://example.com/index.php?endpoint=login&access_key=12345
Obviously, I have tried many htaccess generators to create an appropriate RewriteRule set.
For example the following (from: http://www.generateit.net/mod-rewrite/index.php):
RewriteEngine On
RewriteRule ^([^/]*)/([^/]*)$ /index.php?endpoint=$1&access_key=$2 [L]
Even though I know for a fact that .htaccess and mod_rewrite is enabled on my server (i tried to setup a test to redirect all requests from example.com to example2.com using htaccess and mod_rewrite, and it worked), I can't get this to work.
I have now spent nearly 2 hours to find for a solution on stackoverflow and other websites, but all my attempts failed.
I hope someone can help me find out the correct way to rewrite my url in the above example.like explained above.
Thanks a lot in advance!
Try with this:
RewriteEngine On
RewriteRule ^([^\/]*)/([^\/]*)$ /index.php?endpoint=$1&access_key=$2 [L]
#-Added-these---^--------^
When tested, here is the result:
Add this to the .htaccess file in your DOCUMENT_ROOT
Assuming login is not variable
RewriteEngine On
RewriteRule ^login/(\d+)$ index.php?endpoint=login&access_key=$1 [L,NC,DPI]
** If login is variable**
This is in case you want to redirect not only for login, but also for urls such as http://example.com/housenumber/12345
RewriteEngine On
RewriteRule ^([^/]+)/(\d+)$ index.php?endpoint=$1&access_key=$2 [L,NC,DPI]
Tested on actual Apache 2.2 and 2.4 :)
I'm using localhost, and in my index.php page I have this code:
<? echo 'LANG IS '.$_GET['lang']; ?>
When I type localhost on the URL it only shows LANG IS, obviously, but if I type localhost/en I see a 404 Not Found message. I have to type localhost?lang=en to show my index.php code. I want to type localhost/en instead of localhost?lang=en and get the same result.
I'm using Apache2 and I have mod_rewrite enabled. I also have a .htaccess file with this code (I have changed and tested it a lot of times):
RewriteEngine on
RewriteRule ^/([a-zA-Z0-9]+|)/?$ index.php?lang=$1 [L,QSA]
I have been reading about .htaccess and clean urls for days but I couldn't make this work. Any ideas? Thank you so much in advance.
Most likely your .htaccess isn't even enabled. Verify it first
To check if your .htaccess is enabled try putting same random/garbage text on top of your .htaccess and see if it generates 500 (internal server) error or not?
It it is not enabled then then you will need AllowOverride All line in <Directory "/var/www/>` section.
Once it is enabled following rule should work for you:
RewriteEngine on
RewriteRule ^(\w+)/?$ index.php?lang=$1 [L,QSA]
Try getting rid of the leading slash in the pattern:
RewriteEngine on
RewriteRule ^([a-zA-Z0-9]+|)/?$ index.php?lang=$1 [L,QSA]
URI's that are sent through rules in the htaccess files have the leading slash stripped off so the pattern needs to omit it.
The problem is probably in the regular expression.
Try with this one:
RewriteEngine on
RewriteRule ^/([a-zA-Z0-9]+)/ /index.php?lang=$1 [L,QSA]
In my page, when I write the url domain.com/abc it uses the htaccess RewriteRule ( posted below) and opens the company-profile.php page, showing the ABC profile. ABC IS AN EXAMPLE. IT MAY BE ANYTHING
However, even I have a domain.com/index.php file, when I write just domain.com and hit enter, it takes me to the company-profile.php page where it supposed to show the index.php file
My question is how can I fix this ?
RewriteEngine On
RewriteRule ^([a-z0-9]+)?$ /domain.com/company-profile.php?cid=$1 [NC,L]
Something like this maybe?
RewriteCond %{REQUEST_URI} !^/$
RewriteCond %{REQUEST_URI} !^/index.(php|html?)
RewriteRule ^(.*)$ profile/company-profile.php?cid=$1 [NC,L]
The first part of your RewriteRule is matching anything that's a combination of letters and numbers and passing it to your /domain.com/profile/company-profile.php script. You need to be more specific on your RewriteRule, i.e:
RewriteEngine On
RewriteRule ^/profile/([a-z0-9]+)?$ /domain.com/profile/company-profile.php?cid=$1 [NC,L]
The above will only match requests beginning with /profile/, so for example /profile/martinbean will be matched.
Is apache your web server. If the answer is yes, You should first check your loaded apache modules to see if the rewrite module is loaded. If not , then try to add this line:
LoadModule rewrite_module /usr/lib/apache2/modules/mod_rewrite.so
to your apache config files . Then try to restart your web server to check if the rewirte rules worked.
Please how can I rewrite
Could anybody please rewrite this url?
http://localhost/display_news_cat.php?news_cat_id=14&p=2
to
http://localhost/display_news_cat/14/2
Thank you
You can do thtat with a .htaccess file
put this in a .htaccess file and place it in de root of your site
apache must have mod-rewrite on
RewriteEngine on
RewriteRule ^news.php news [QSA,L]
try this for all files
RewriteEngine on
RewriteRule ^(a-zA-Z0-9).php $1 [QSA,L]
Assuming you have installed the rewrite module, you could put this in your virtualhost:
RewriteEngine ON
RewriteRule /newsdev/news /newsdev/news.php [L]
Check this site for more information on RewriteRule:
http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewriterule
But I doubt this is the best way. The rewritemodule is usually not the most efficient way to do easy things like these. Depends on what other complex things you want to rewrite.
With mod_rewrite
http://www.easymodrewrite.com/example-extensions
You need to work with the .htaccess file in your site root... you'll have to create one if it's not there.