want to rewrite urls like site.com/software to wp-content/themes/dir/software.php and something is not working.. Here's what I have:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteRule ^software wp-content/themes/dir/software.php [L]
Thanks!
Rewrite rules are processed in the order that they are encountered. In this case, every request is getting pushed to index.php before your software rule is encountered (assuming that software doesn't exist in the system as a directory or file). The [L] on the end of the first rule tells Apache to stop reading rules, so it doesn't even bother processing the next one.
Try this:
RewriteEngine On
RewriteBase /
RewriteRule ^software wp-content/themes/dir/software.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
Related
i have been pulling my hair out for 3 days. i ve checked forums and tutorials but i just dont get it. i have a url of
http://localhost/gallery/2012/2
but i also need to get
http://localhost/gallery/2
this is my htaccess file
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9_-]+)/([0-9-]+)/([0-9-]+)/?$ index.php?page=$1&date=$2&pagenum=$3 [L]
RewriteRule ^([a-zA-Z0-9_-]+)/([0-9-]+)/?$ index.php?page=$1&date=$2 [L]
RewriteRule ^([a-zA-Z0-9_-]+)/?$ index.php?page=$1 [L]
</IfModule>
how would i go about adding another rule
RewriteRule ^([a-zA-Z0-9_-]+)/([0-9-]+)/?$ index.php?page=$1&pagenum=$2 [L]
I'm using Apache 2.2 with two servers:
Development: localhost/project/public
Production: www.example.com
I have an existing rewrite rule for clean urls (to remove 'index.php' from the url).
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
I have one special route that only works if a trailing slash is present:
special route (development): localhost/public/documentation/
special route (production): www.example.com/documentation/
How do I add a rewrite rule to my existing .htaccess to always add a trailing slash, but only for the documentation route?
You just need to add another RewriteRule that matches only against /documentation i.e. without a trailing slash. The first rule adds the trailing slash and then your existing rule adds the index.php.
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^(documentation)$ $1/ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
If you would like the browser's address bar to also reflect the trailing slash change the rule to
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteRule ^(documentation)$ $1/ [R=301,NC,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
Don't forget to add these directives first once per .htaccess file:
Options +FollowSymlinks
RewriteEngine on
And then you can try this:
RewriteRule ^/?(documentation)$ /$1/ [R,NC,L]
Or this:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} (.+)/([^/]+)$
RewriteRule ^/?(documentation)/(.+)$ /$1/$2/ [R,NC,L]
I'm confused about your question..
I am using this mod-rewrite rule to redirect the just the homepage of my site to the /it/ sub-directory on the same site.
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RedirectMatch 301 ^/$ http://www.example.com/it/
However, I want to exempt this url from being redirected
http://www.example.com/?act=25
How can I write an exempt condition to do this?
Found a solution
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteCond %{QUERY_STRING} !^act=(.*)$ [NC]
RewriteRule ^$ http://www.example.com/it/
Oh, and RewriteCond does not work with RedirectMatch in case you didn't know (I didn't and wasted hrs because of it)
working .htaccess config:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_URI} ^thumbs/(.*)$
RewriteRule ^(.+)$ /index.php [L,QSA]
All 404 queries to /thumbs/ folder not must be catched by /index.php script. Why top .htaccess config work and bottom config not work?
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_URI} !^/thumbs/(.*)$
RewriteRule ^(.+)$ /index.php [L,QSA]
Apache 2.2.9, Debian
REQUEST_URI contains the requested URI path and does always start with a slash.
So the pattern ^thumbs/(.*)$ does never match as it’s missing the leading /. But the other condition, !^/thumbs/(.*)$, should match every request that’s URI path does not start with /thumbs/.
I think it's because the first slash in
RewriteCond %{REQUEST_URI} !^/thumbs/(.*)$
I have a doubt about url rewriting using apache mod_rewrite. I am a newbie in mod_rewrite and I don't have any experience in regex.
What I want to do is to:
Rewrite / To /web/content/public/
Rewrite /clients/ To /web/content/clients/
How can I achieve above things.
I tried:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^/clients/$ web/content/clients/ [L]
RewriteRule ^(.*)$ web/content/public/$1 [L]
</IfModule>
But it doesn't work. What can I do?
^(.*)$ includes the slash. So don't include the slash in the rewritten pattern.
But include a root slash at the head of your rewritten pattern.
RewriteRule ^/clients(.*)$ /web/content/clients$1 [L]
RewriteRule ^(.*)$ /web/content/public$1 [L]
Check the apache access log and error log to see what kind of request URL comes back.
Please check the documentation, especially the list labeled "Here are all possible substitution combinations and their meanings:"
Try this:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -l
RewriteRule ^ - [L]
RewriteRule ^/clients/$ web/content/clients/ [L]
RewriteRule ^/(.*)$ web/content/public/$1 [L]
And if you want to use that rules in a .htaccess file, remove the leading slash from the patterns.