I am trying to use like
www.site.com/somename
from two different pages. and i am using htaccess.
#1st condition
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.+) profile.php?username=$1 [QSA,L]
#2nd condition
RewriteCond %(REQUEST_FILENAME) !-f
RewriteCond %(REQUEST_FILENAME) !-d
RewriteRule (.+) clinicprofile.php?profilename=$1 [QSA,L]
It works if i only use for one of above page condition, But when i use both conditions 404 page is showing.
Please try to solve my problem.
Thanks to the suggestions,
what i have implemented is
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.+) profile.php?username=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^clinic/(.+)$ /clinicprofile.php?profilename=$1 [L]
clinic word need to added.
Related
I am learning PHP and HTACCESS atm.
I have a problem where i use 4 different GET variables. x,y,z,w.
I need to create an URL structure which both can be.
mysite.com/x/y
but also
mysite.com/x/z
and different other combinations.
I
I have tried this in HTACCESS, but it only work if its the same kind of structure, and not with other combnations:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)$ index.php?x=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)$ index.php?x=$1&y=$2 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/([^/]+)$ index.php?x=$1&y=$2&z=$3 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)$ index.php?x=$1&y=$2&z=$3&w=$4 [L]
Specify [QSA] (Query string append) so you may pass a query string after your url.
Sample Code
RewriteEngine On
RewriteRule ^book/([^/]*)\.html$ book.php?title=$1 [QSA,L]
I have a long URL like this http://example.com/interview/folder1/folder2/xxx. I need that page to be opened also in the short form like this http://example.com/interview/xxx.
I have tried this, it didn't help
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_URI} !^interview/folder1/folder2/
RewriteRule (.*) interview/$1
Please note that this is an excerpt from the htaccess which is much larger.
What am I doing wrong?
You can try this .htaccess file:
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_URI} !^interview/folder1/folder2/
RewriteRule ^interview/(.*)$ /interview/folder1/folder2/$1 [L]
I have these two rules next to each other
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/\.]+)?$ category-groups.php?furl=$1 [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/\.]+)-([^/\.]+)?$ product.php?id=$2&head=$1 [QSA]
This works
/category-groups.php?furl=my-category-page
redirects to
/my-category-page
This doesn't work
/product.php?id=100&head=this-product
does not redirect to
/this-product-100
The product.php page is actually bounced to the category-groups.php page.
I hope that makes sense. I've tried many things but can't figure out to solve it
Thanks
You need to swap the order of your rules and make the regex match numbers:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/\.]+)-([0-9]+)?$ product.php?id=$2&head=$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/\.]+)?$ category-groups.php?furl=$1 [QSA,L]
otherwise ^([^/\.]+)?$ will always just match everything.
I have the current rewrite rule:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ index.php?page=$1 [L,QSA]
This works wonderfully for http://www.example.com/something but I would also like to be able to have sub pages, ie: http://www.example.com/something/something. I would like it to take the form of:
index.php?page=$1&subpage=$2
or
index.php?page=something&subpage=$1
Can someone please point me in the right direction?
Give this a go:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/?$ index.php?page=$1&subpage=$2 [L,QSA]
You can also make both in one rule like this:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(?:([^/]+)|)(?:/([^/]+)|)/?$ index.php?page=$1&subpage=$2 [L,QSA]
i have a Problem with my .htaccess/mod_rewrite:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^sometest/(.+)/page/([0-9]+)$ index.php?main=sometest/$1&page=$2
RewriteRule ^(.+)$ index.php?main=$1 [QSA]
This does not work. If i visit my website the css files are not included.
I include them like "/assets/css/blabla.css".
If i delete just one RewriteRule (doesn't matter which one) it works. But i need both rules.
You must use skip flag skip|S=numfor this.
like :
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d [NC,OR]
RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteCond %{REQUEST_URI} ^(.*)/([^/]+)\.([^/]+)$
RewriteRule ^ - [S=2,L]
RewriteRule ^sometest/(.+)/page/([0-9]+)$ index.php?main=sometest/$1&page=$2 [S=1,L]
RewriteRule ^(.+)$ index.php?main=$1 [QSA,L]
see this page for more information http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewriterule