I am trying to show the contents of http://example.com/about.php under http://example.com/seller/samsung/about.php where samsung is a dynamic and non-existing folder. I have tried the following code:
RewriteRule ^seller/([^/]+)/(.*)$ ./$1
It works when I do it manually like this:
RewriteRule ^seller/samsung/(.*)$ ./$1
Should be [^/]+ without parenthesis ()
RewriteRule ^seller/[^/]+/(.*)$ ./$1
Related
I have a TYPO3 extension for content output. If I call the contents, the name of the extension is always called:
example.com/?tx_nameoftheextension[id]=1234
The number 1234 is a changing ID. I would like a resolution of the extension to:
example.com/detail/1234
I tried a little bit, but the following syntax does not work for me:
RewriteCond %{QUERY_STRING} ^tx_\nameoftheextension\[id\]=1234$
RewriteRule .* example.com/detail/1234? [R=301,L]
Of course the upper one would work with RealUrl, but only with database connection, I would like to solve this without.
But this is only the beginning, I have different display options in the extension which append a longer extension name, which I would like to rewrite that didnĀ“t run with RealUrl:
example.com/?tx_nameoftheextension[action]=showN&tx_nameoftheextension[n_id]=1234
to
example.com/detail/n/1234
Try with this .htaccess syntax:
RewriteCond %{QUERY_STRING} ^tx_\nameoftheextension\[action\]=showN&tx_\nameoftheextension\[n_id\]=1234$
RewriteRule .* example.com/detail/n/1234? [R=301,L]
I am trying to change my url through .htaccess in the following way
Original URL: http://www.example.com/latest-news.php?id=2/topic=testing
Rewritten URL:http://www.example.com/2/testing
Rule for .htaccess
RewriteRule ^([^/]*)/([^/]*)$ /latest-news.php?id=$1&topic=$2 [L]
This is working fine but the other files which are existing in a folder are not opening. The url is opening as www.example.com/testing/foo.php but content of the page is of http://www.example.com/2/testing
Can you try with a similar rule like the one bellow?
RewriteRule ^([0-9]+)/([a-zA-Z])$ /latest-news.php?id=$1&topic=$2 [L]
Can't really test it on my server but you can adapt it to suit your needs
RewriteEngine On
RewriteRule ^([0-9]+)/([^/]*)$ /latest-news.php?id=$1&url=$2 [L]
Since second part consists characters and digits So I modify the answer of stoica. Thanks #stoica
I want to do a simple redirect so that a request for app/scans/large/as89q6dfa.jpg results in app/scans/medium/as89q6dfa.jpg, etc. The trouble is that this app will be used on a few domains with different base paths. The code I've tried keeps rewriting to the absolute base path of the site and the app is actually a variable number of folders deep on the site. Is there a generalized way to do a redirect like this, without hard-coding the base path?
Here's my file and folder scructure:
app/.htaccess
app/scans/large
app/scans/medium
So the .htaccess rules should work for:
includes/app/scans/large
inc/app/scans/large
script/engine/app/scans/large
Here's my first attempt:
RedirectMatch 301 scans/large/(.*) scans/medium//$1
Here's my second attempt:
RewriteEngine On
RewriteBase /
RewriteRule ^scans/large/(.*) scans/medium/$1 [R=301,L]
When you use the "^" caracter it means that the regex will search for the string "scans/large" in the BEGINNING of the URL.
So as the base is "/", it won't work on "includes/app/scans/large/omg" because "scans" it's not in the beginning of the string.
Try this solution:
RewriteEngine On
RewriteBase /
RewriteRule (.*)scans/large/(.*) $1scans/medium/$2 [R=301,L]
It worked perfectly with the URL:
http://www.example.com/includes/app/scans/large/omg
That redirects to:
http://www.example.com/includes/app/scans/medium/omg
You can do more tests on it here: link
You can actually get RewriteBase be determined dynamically.
RewriteEngine On
# determine BASE dynamically
RewriteCond %{REQUEST_URI}::$1 ^(.*?/)(.*)::\2$
RewriteRule ^(.*)$ - [E=BASE:%1]
RewriteRule ^scans/large/(.*)$ %{ENV:BASE}scans/medium/$1 [R=301,L,NC]
I have URL like this: http://example.com/apple_a/
I am using this rule:
RewriteEngine On
RewriteRule ^([^_]*)-+(.*)$ $1_$2 [L,NC]
this is replacing other URL's like http://example.com/apple/a_a/a_b to "http://example.com/apple/a-a/a-b" (underscore with dashes) but when I write "_" in first directory like this "http://example.com/apple-a/a-a/" then its throwing 404 error.
So I wants that working somehow. Please help.
Correct rule will be:
RewriteEngine On
RewriteRule ^([^-]*)-+(.*)$ $1_$2 [L,NC]
You have ([^_]*) instead of ([^-]*)
I am working with a CMS, and up until today its been fine.
But i have discovered that the mod rewirte only works if the website is in the root directory. If I put the entire CMS into a folder, i get a 404.
Please help!
RewriteEngine on
Options +FollowSymLinks
RewriteRule ^([^/\.]+)/?$ /index.php?1=$1 [L]
RewriteRule ^([^/\.]+)/([^/\.]+)/?$ /index.php?1=$1&2=$2 [L]
RewriteRule ^([^/\.]+)/([^/\.]+)/([^/\.]+)/?$ /index.php?1=$1&2=$2&3=$3 [L]
RewriteRule ^([^/\.]+)/([^/\.]+)/([^/\.]+)/([^/\.]+)/?$ /index.php?1=$1&2=$2&3=$3&4=$4 [L]
RewriteRule ^([^/\.]+)/([^/\.]+)/([^/\.]+)/([^/\.]+)/([^/\.]+)/?$ /index.php?1=$1&2=$2&3=$3&4=$4&5=$5 [L]
RewriteRule ^([^/\.]+)/([^/\.]+)/([^/\.]+)/([^/\.]+)/([^/\.]+)/([^/\.]+)/?$ /index.php?1=$1&2=$2&3=$3&4=$4&5=$5&6=$6 [L]
RewriteRule ^([^/\.]+)/([^/\.]+)/([^/\.]+)/([^/\.]+)/([^/\.]+)/([^/\.]+)/([^/\.]+)/?$ /index.php?1=$1&2=$2&3=$3&4=$4&5=$5&6=$6&7=$7 [L]
Then you need to add the subfolder to your rewrite rule like this, for all of your rules.
RewriteRule ^([^/\.]+)/?$ /subfolder/index.php?1=$1 [L]
With your configuration apache will search for the index.php file in the root directory
Your script is extracting data that are between slashes like:
/test1/test2/ transfers into /index.php?1=test1&2=test2
but since you started using folder it works like:
/folder/test1/test2/ transfers into /index.php?1=folder&2=test1&3=test2
so the folder name is breaking your structure, you will need to fix every line with folder name or expression like this:
RewriteRule ^[^/\.]+/([^/\.]+)/?$ /folder/index.php?1=$1 [L]
So you will need to fix both regular expression and new path on every line, just replace folder with name of your folder and add [^/\.]+/ at start
If that doesnt work you may just need to fix regular expression only without adding /folder to the second part of line