I have the following:
RewriteRule ^tribute-acts/([^/.]*)/?$ /entertainment/act-view.html?act_name=$1 [L,QSA,NC]
which changes:
http://mysite.com/entertainment/act-view.html?act_name=elvis
to:
http://mysite.com/tribute-acts/elvis
Works great, but what if the tribute-acts part was dynamically generated and different for each link? Therefore endless possibilities...
Can I use a wildcard instead of tribute-acts/ ?
I tried the following, using (.*), but it didn't work:
RewriteRule ^(.*)/([^/.]*)/?$ /entertainment/act-view.html?act_name=$1 [L,QSA,NC]
You can try this rule:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^[^/]+/([^/]*)/?$ /entertainment/act-view.html?act_name=$1 [L,QSA]
Related
I have the following link:
http://example.net/invite/12345
I need to replace it to http://example.net/wedding/index.php?main_page=invite&invite_code=12345
I've got the following....but I'm just not hitting the nail here.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?(.*)$ /wedding/index.php?main_page=invite&invite_code=$1 [L,QSA]
It's taking me to:
http:///example.net/wedding/index.php?main_page=invite&invite_code=invite%2F12345
Thanks for the help!
$1 is a reference to the capturing group (.*), so:
RewriteRule ^invite/(.*)$ /wedding/index.php?main_page=invite&invite_code=$1 [L,QSA]
Let's suppose that I have a file in the filesystem like this:
/documentroot/domains/foo/files/resource.html
I want to write a rule so that http://foo.example.com/resource.html serves the file /domains/foo/files/resource.html. But if the request URL is http://bar.example.com/resource.html, it should look inside /domains/bar/files/resource.html. What I've accomplished so far is this, which works correctly:
RewriteEngine On
RewriteCond "%{DOCUMENT_ROOT}/domains/foo/%{REQUEST_URI}" -f
RewriteRule ^ domains/foo/%{REQUEST_URI} [QSA,L]
How can I generalize this, for any domain name? I was thinking of applying a regular expression to the %{SERVER_NAME} variable, but I can't find a way to achieve this.
You can use this rule:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_HOST} ^(?!www\.)([^.]+)\. [NC]
RewriteRule !^domains/ domains/%1/files%{REQUEST_URI} [L,NC]
I have this on my .htaccess
RewriteEngine On
RewriteRule ^([^/\.]+)/?$ ?link=$1 [L]
My link is example.com/?link=sometext
I want to acces that by example.com/sometext and this^ rewrite does that
Now my links has changed, they are now in this format-> 'some.text' . With a dot. The current htaccess gives me 404
How can I make this work ? I tried generators but they only gave me 500 errors
Remove . from your character class and have your rule as this:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/?$ ?link=$1 [L,QSA]
I have the standard htaccess which just catches all and puts it into one url parameter which is later processed in code...
RewriteRule ^config/ - [F]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
I use "pretty" url params like
/some/route/param1/value1/param2/value2
but now I need an ability to add "regular" url params like
/some/route/param1/value1?param2=value2¶m3=value3 etc
I tried adding
RewriteRule ^(.*)\?(.*)$ index.php?q=$1&p=$2 [L,QSA]
before the existing rule, but it won't work properly (and I suspect it would only work with one parameter).
Try this:
RewriteRule ^([^?]+)\?(.*)$ index.php?q=$1&p=$2 [L,QSA]
I'm trying to handle multiple areas of an application, but the URLs are not being rewrited as expected.
This is the .htaccess file:
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^division/(.*)/section/(.*)$ ./index.php?division=$1§ion=$2
RewriteRule ^division/(.*)$ ./index.php?division=$1
RewriteRule ^area/(.*)$ ./index.php?area=$1
What's expected:
If the URI matches division/some_division/section/some_section rewrite to index.php?division=some_division§ion=some_section
If no section (section/some_section) is defined, go to the second rule -
If the URI matches division/some_division rewrite only to index.php?division=some_division
If no division is defined, and the URI matches area/some_area rewrite to index.php?area=some_area
I'm almost sure I can combine the two first rules, I've tried this regex but it didn't work:
^division/(.*)( /section/(.*) )?$
It supposed to make /section/some_section an optional value.
Unfortunately nothing works. Any ideas?
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^division/(.*)/section/(.*)$ ./index.php?division=$1§ion=$2 [QSA,L]
RewriteRule ^division/(.*)$ ./index.php?division=$1 [QSA,L]
RewriteRule ^area/(.*)$ ./index.php?area=$1 [QSA,L]