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
Related
like a title i have a problem with this rewrite rule
I write this
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !\.(font|css|js|images|remote) [NC]
RewriteCond %{REQUEST_URI} !^/(font|css|js|images|remote/.*)$ [NC]
RewriteRule ^index$ /page/index [QSA,L]
RewriteRule ^(.*)/(.*)$ /page/article&category=$1&post=$2 [QSA,L]
When i call ajax remote from /remote/check-function.php from pages he load full /page/post with variable sent by ajax.
How i can resolve this issue
Thanks in advance.
Best.
The RewriteCond only applies to the RewriteRule that comes immediately. Properly that the url /remote/check-function.php matches the last rule and is rewritten. You should add RewriteCond to check whether the request matches the existing files / directories before applying the last rule:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/(.*)$ /page/article&category=$1&post=$2 [QSA,L]
Is there any possibility to rewrite url's with get variables globally, instead of specific files?
Changing
http://example.com/{something}?id=1
To:
http://example.com/{something}/id/1
Or without the word id:
http://example.com/{something}/1
This is what I got so far:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/$ $1.phtml
RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.phtml
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
With this I could remove the .phtml extension
I hope there is a specific answer for this!
I am assuming something to be a php file,
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\w-]+)/id/([\d]+)$ $1.php?id=$2 [L] #with id in between
or
RewriteRule ^([\w-]+)/([\d]+)$ $1.php?id=$2 [L] #without id in between
You have to make sure rules are not conflicting.
I have trying to figure out how to get working in subfolder "admin" the same thing which works in root dir, problem is I don't know how to do that.
Currently I have:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ?arg=$1 [L,QSA]
# /
RewriteCond %{REQUEST_URI} !\.[[:alnum:]]+$
RewriteRule ^(.+[^/])$ /$1/ [R=301]
Now it works like:
http://example.com/page translate into http://example.com/?arg=page
What I would like to do in addition is this:
http://example.com/admin/page translate into http://example.com/admin/?arg=page
I don't know at all how to make that happen, can somebody help me please?
Thanks
You can use these rules with appropriate RewriteBase:
RewriteEngine On
RewriteBase /admin/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule [^/]$ %{REQUEST_URI}/ [L,R=301,NE]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ?arg=$1 [L,QSA]
Or just add
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/admin/(.*)$ admin/index.php?arg=$1 [L,QSA]
i'm working a small project in which i'm using .htaccess to make URLs short and sweet. But it's not working. Here's the code:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php #removing .php extension
RewriteCond %{SCRIPT_FILENME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^category/(.+)$ category.php?category=$1 #removing get variables
By using the first condition it's removing the use of .php extension in the URL bar. And the second condition is added with an intention to remove the GET variables. URL is something like this:
www.example.com/category.php?category=latest
and i want this url to be look like this:
www.example.com/category/latest
Flip the order otherwise first rule will catch this category URI also.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^category/(.+)$ category.php?category=$1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [L]
I want to redirect request on same page by excepting one page by using .htaccess file. The code that i have used
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/index.php
RewriteCond %{REQUEST_URI} (/|\.php|\.html|\.htm|\.feed|\.pdf|\.raw|/[^.]*)$ [NC]
RewriteRule (.*) index.php
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
Dose anyone know how i can take condition on a single page named "register.php"? Means i want to open register.php now its open index.php.
Thanks in advance
Change your code to:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/(index|register)\.php$ [NC]
RewriteRule ^(.+?\.(php|html?|feed|pdf|raw)|[^.]*)$ index.php [L,NC]
RewriteCond %{ENV:REDIRECT_STATUS} !200
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/(index\.php|register\.php)$
RewriteRule ^(.*)$ index.php? [L,R=301,E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]