I want to convert the following .htaccess rules to lighttpd rewrite rules
RewriteEngine On
RewriteRule ^images/.*$ index.php
RewriteCond %{REQUEST_URI} !(^/_)|(error\.html)$ [NC]
RewriteRule ^.*$ index.php
I don't have experience with lighttpd, but I need to start script on lighttpd server. How do I convert these rules andwhere do I need to place them so the script works?
Solved by this:
#/mnt/sdcard/pws/rewrite.conf
# rewrite rules
url.rewrite-if-not-file += (
"^images/.*$" => "index.php",
"^([^\?]+)(?:\?(.*))$" => "index.php?_route_=$1&$2",
"^.*$" => "index.php"
)
# //rewrite rules
Related
I would like to redirect via a RewriteRule (mod_rewrite) enabled in httpd.conf my URL:
https://mysite.domain.tld/index_php_file.php?ab=ident_keys&ac=5GU7VBNAH45DA5
TO:
https://mysite.domain.tld/index_php_file.php?ab=ident_key_1024&ac=5GU7VBNAH45DA5
I have tried it with a number of rules without luck:
RewriteCond %{HTTP_HOST} hmysite.domain.tld
RewriteRule ^/index_php_file\.php\?ab=ident_keys&ac=$ https://hmysite.domain.tld/index_php_file.php?ab=ident_key_1024&ac= [R=301,L,QSA]
nor
RewriteCond %{QUERY_STRING} ^ac=(.*)$
RewriteRule ^/?([a-z-0-9-_.]+)$ /$1/index_php_file.php?ab=ident_key_1024&ac=%1 [L,R=301]
seems to rewrite the URL.
Any suggestions on what I'm missing?
Thank you very much.
I found the solution, it may help someone.
RewriteCond %{QUERY_STRING} ac=([A-Z0-9]+)
RewriteRule ^/?([-a-zA-Z0-9_+]+)$ index_php_file.php?ab=ident_key_1024&ac=$1 [R=301,L]
It is enough to look for the string (containing UPPERCASE chars and numbers only) with the RewriteCond and rewrite the URL RewriteRule to the desired format and append the value of the variable from the query.
Do not forget to enable the mod_rewrite module within Apache. To take effect a restart is also necessary of course.
I am trying to rewrite some URLs using my .htaccess file and the following syntax:
RewriteEngine On
RewriteRule ^movie/([0-9]+)/$ movie.php?id=$1
Basically, the URL http://screeningapp.co.uk/movie.php?id=771316320 should be rewritten to http://screeningapp.co.uk/movie/771316320, but that's not happening and I'm not sure why.
Thanks!
RewriteEngine On
RewriteRule ^movie/([0-9]+)/?$ /movie.php?id=$1 [L,nc]
#if you wanna redirect movie.php?id=1 to movie/1/
RewriteCond %{QUERY_STRING} ^id=([0-9]+)($|&)
RewriteRule ^movie.php$ /movie/%1? [R=301,L,NC]
What I'm looking to do is rewrite the url so that one of the directories are hidden. For example;
http://www.example.com/home/example.html
to
http://www.example.com/example.html
As I'm new to .htaccess and mod_rewrite, is this something that can be done?
This should work:
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/home/.*$
RewriteRule ^(.*)$ /home/$1 [L]
Something like this should work.
RewriteEngine On # Turn on the rewriting engine
RewriteRule ^example.html$ /home/example.html [NC,L]
So, I'm trying to move a site over to Lighttpd but I can't seem to get the URL re-writes correct - any idea what these would translate to in Lighttpd-speak?
RewriteRule ^portfolio/([^/]+) /index.php?portfolio=$1 [NC]
RewriteCond $1 ^(portfolio|news|about|contact|home|P[0-9]{2,8}) [NC]
RewriteRule ^(.*)$ /index.php/$1 [L]
I've tried a few configurations to no avail:
"^/(?!portfolio)(.+)/?$" => "/index.php?portfolio=$1"
"^/portfolio/(\d+)(?:\?(.*))?" => "/index.php?portfolio=$1"
I think this will work for you:
"^(/portfolio/.*)$" => "/index.php?portfolio=$1"
That will rewrite all urls like example.com/portfolio/123 to index.php?portfolio=123
Use just ^(.*)$ to rewrite everything to one url
I am moving the old server to archive.example.com, and the new server will continue to run on example.com while all www URLs are canonicalized to either example.com or archive.example.com and should deal with the trailing slash issue.
The old server has many directories so everything needs to redirect to archive.example.com while retaining the path information, except for a few directories which will run on the new server. The directories I do NOT want to redirect and will remain for the new server are:
/ (root)
/static
/blog
/about
For example:
example.com => example.com
www.example.com => example.com
www.example.com/ => example.com/
example.com/blog => example.com/blog
www.example.com/blog => example.com/blog
www.example.com/blog/ => example.com/blog/
All other directories should redirect to archive.example.com. For example:
example.com/docs => archive.example.com/docs
www.example.com/docs => archive.example.com/docs
www.example.com/docs/ => archive.example.com/docs/
example.com/library/images => archive.example.com/library/images
www.example.com/library/images => archive.example.com/library/images
www.example.com/library/images/ => archive.example.com/library/images/
Here is what I have in my httpd.conf file:
ServerName example.com
ServerAlias www.example.com
UseCanonicalName On
# canonicalize www.example.com to example.com
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ $1 [R=301]
# redirect everything to archive.example.com except for a few directories
RewriteCond %{REQUEST_URI} !^(/|/static|/blog|/about)$
RewriteRule ^/(.*)$ http://archive.example.com/$1 [NC,R=301,L]
Is this correct and/or is there a more precise way?
RewriteEngine On
RewriteCond %{HTTP_HOST} !^gotactics.net$ [NC]
RewriteRule ^(.*)$ http://gotactics.net/$1 [L,R=301]
This will remove all www. Im sure you can change it too do different if needed.
I believe I found my issue -- it was with the RewriteRule that redirected to the old site.
This is what I had when I posted the question:
# redirect everything to archive.example.com except for a few directories
RewriteCond %{REQUEST_URI} !^(/|/static|/blog|/about)$
RewriteRule ^/(.*)$ http://archive.example.com/$1 [NC,R=301,L]
...and I rewrote this to:
# redirect everything to archive.example.com except for a few directories
RewriteCond %{REQUEST_URI} !^/$
RewriteCond %{REQUEST_URI} !^/static.*$
RewriteCond %{REQUEST_URI} !^/blog.*$
RewriteCond %{REQUEST_URI} !^/about.*$
RewriteRule ^(.*)$ http://archive.example.com%{REQUEST_URI} [NC,R=301,L]
Here's why.
First, as you can see, I broke up the single rewrite condition into four separate conditions because this will enable me to cleanly add more directories for exclusion as the new site grows.
You will also notice that I added a dot-star after /static, /blog/ and /about so that it will match on any path in those directories and not just the top level.
Finally, on the RewriteRule line I removed the leading slash from the pattern and changed the trailing /$1 to %{REQUEST_URI} . I don't need to store any variables from the pattern here -- I just need to change the server name -- so instead of extracting the path from the pattern, I made it more explicit by using the same %{REQUEST_URI} variable that was used on the previous four lines.
BTW: One of the reasons this was causing confusion for me at first was because Chrome was sometimes caching the DNS/path info -- doing a Ctrl-F5 to purge the cache will enable you to see your changes.