I have this htaccess file:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
DirectoryIndex index.php
RewriteRule ^doit$ doit.php [L]
RewriteRule ^([\$\.A-Za-z0-9_-]+)$ follow.php?follow=$1 [QSA,L]
But when i try to go in the index page, everytime showing follow.php page, even doit page show this last one.
Any fix for this issue please ?
Thank's.
RewriteCond technically applies only to the first RewriteRule, so
please try using something like this:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^([\$\.A-Za-z0-9_-]+)$ follow.php?follow=$1 [QSA,L]
#RewriteConds for this rule
RewriteRule ^doit$ doit.php [L]
DirectoryIndex index.php
I hope be useful. Regards.
Related
I have a web site working on localhost for now.
I send some data with get method to another controller
When I send data my url is look like:
http://localhost/book/Control/?kolon=&satir=unknown&modals=infox&bookid=4555
but i want to it look just like:
http://localhost/book/4555
I tried editing my .htaccess file like below but it does not work:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
RewriteRule ^(.*)$ Control/?kolon=&satir=unknown&modals=infox&bookid=$1 [L]
</IfModule>
how can I fix it?
You want the pretty URLs through htaccess.
The following is tested and works works:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^book/(\d+)*$ ./book/Control/?kolon=&satir=unknown&modals=infox&bookid=$1
Refer: https://code.tutsplus.com/tutorials/using-htaccess-files-for-pretty-urls--net-6049
Try to change it in that way:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^book/(.*)$ Control/?kolon=&satir=unknown&modals=infox&bookid=$1 [L,QSA,NC]
If bookid it's a numeric value you can use:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^book/([0-9]+)$ Control/?kolon=&satir=unknown&modals=infox&bookid=$1 [L,QSA,NC]
I have the following htaccess file which works for my application:
Options -MultiViews
RewriteEngine On
Options -Indexes
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
How to change urls like http://example.com/de/contact to
http://example.com/contact ?
I tried something like:
RewriteCond %{REQUEST_URI} !^de/
RewriteRule ^(.*)$ de/$1 [L]
I'm trying to rewrite some dynamic page url in which data is taken from database with slug like "this-is-a-link".
Options +FollowSymlinks
RewriteEngine On
RewriteBase /testweb/
RewriteCond %{REQUEST_FILENAME} !-d [NC]
RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteRule ^(.*)$ faq_pages.php?page=$1 [QSA,L]
It works fine with http://www.test.com/testweb/this-is-a-link
But I need to change the rewrite rule based on any link clicked as below.
http://www.test.com/testweb/faq/this-is-a-link, 'testweb/news/this-is-another-link','/testweb/testimonials/test-link'
The "faq_pages.php" in the above RewriteRule should be changed to "news_pages.php". How can I have it dynamically so that I can use for every page with same htaccess or how can I check and rewrite the value to different pages in htaccess.
Also please advice me how to correct below code.
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^(.*)\.html$ faq_pages.php?page=$1
I need to show html urls in the address bar like '/testweb/this-is-a-link.html' or '/testweb/faq/this-is-a-link.html'
Edit: By the help of Jon Lin I have updated my codes as below.
Options +FollowSymlinks
RewriteEngine On
RewriteBase /testweb/
RewriteCond %{REQUEST_FILENAME} !-d [NC]
RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteRule ^faq/(.*?)/?$ faq_pages.php?page=$1 [QSA]
Now both below conditions are working :
/testweb/faq/another-faq-test.html,
/testweb/faq/another-faq-test.html/
As I don't have any sub-folder with name 'faq' the template files(images/css/js etc) in root folder are not loading.
How can I fix it?
Thanking you
Are you looking for something like this?
Options +FollowSymlinks
RewriteEngine On
RewriteBase /testweb/
RewriteCond %{REQUEST_FILENAME} !-d [NC]
RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteRule ^faq/(.*)$ faq_pages.php?page=$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-d [NC]
RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteRule ^news/(.*)$ news_pages.php?page=$1 [QSA,L]
i am writing RewriteRule(s) on htaccess which decides which page it redirect to based on the number of parameters.
for example, "http://mysite.com/tommy"
this will redirect to "mysite.com/user.php?user=tommy"
whereas, "http://mysite.com/tommy/pets"
will redirect to "mysite.com/show.php?user=tommy&category=pets"
note, the first URL has only one parameters and it redirects to user.php and second URL has two parameters and it redirects to show.php instead.
please help, and thanks in advance!
Currently...
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^([^/]*)/?(.*)$ category.php?userId=$1&category=$2 [QSA,L]
RewriteRule ^(.*)$ user.php?userId=$1 [QSA,L]
</IfModule>
Done, for anyone else who need this too...
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^([a-zA-Z0-9_-]+)$ user.php?userId=$1 [L]
RewriteRule ^([a-zA-Z0-9_-]+)/$ user.php?userId=$1 [L]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$ category.php?userId=$1&category=$2 [L]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/$ category.php?userId=$1&category=$2 [L]
i have a htaccess problem
all urls will redirect via access:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?load=content&url=$1
Domain www.domain.de/nicepage will redirect to www.domain.de/index.php?load=content&url=nicepage
Now I would like to redirect 'subfolder':
from www.domain.de/faq/nicefaq to www.domain.de/index.php?load=faqdetail&url=nicefaq
That's what I am try:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?load=content&url=$1
RewriteRule ^faq/(.*)$ index.php?load=faqdetail&url=$1
This does not work. everytime i call the page i will redirect to load=content.
Can You help me pls?
thanks in advance and best regards
Maddin
Both RewriteRules match against the same condition. As the first you wrote matches everything, the second is never reached. Just change the order:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^faq/(.*)$ index.php?load=faqdetail&url=$1
RewriteRule ^(.*)$ index.php?load=content&url=$1
Hope this helps...
Try this code in your .htaccess file:
Options +FollowSymlinks -MultiViews
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^faq/(.*)$ index.php?load=faqdetail&url=$1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/+faq [NC]
RewriteRule ^(.*)$ index.php?load=content&url=$1 [L,QSA]