htaccess - rewrite rule to hide details in URL - .htaccess

This is the current rule I want to modify:
RewriteCond %{REQUEST_URI} m.*
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^m(.*)$ articles.php?$1
The result is:
http://www.mywebsite001.com/m/45/Details-I-Want-To-Hide/
I would like to get this result:
http://www.mywebsite001.com/m/45/
(ending by a slash)

Related

Rewrite rule for htaccess

Hi how can I change my url http://localhost/worldofcontrol/search/ic3500a192c to http://localhost/worldofcontrol/ic3500a192c. how to change in htaccess
RewriteEngine On # Turn on the rewriting engine
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([A-Za-z0-9-]+)/?$ search/product_details.php?id=$1 [NC,L]

Using an IF statement in a HTACCESS ReWrite rule

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9-/_]+)/?$ index.php?id=$1 [L,QSA]
the above i have in my htacces file which rewrites directory/page to index.php?id=directory/page
thats working fine.
I also want to be able to add the following to it:
domain.com/sections/page rewrites to index.php?section=1&id=page
domain.com/sections/page2 rewrites to index.php?section=1&id=page2
domain.com/page rewrites to index.php?id=page
the ID is going to be different for each page
You have to take a look at RewriteCond and RewriteRule directives.
That's a sample .htaccess based on your edit.
RewriteEngine On
# This will process the /sections/(.*) requests, ?section=1 will be appended to query string
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^sections\/(.*)?$ index.php?section=1&id=$1 [L,QSA]
# This will process the other requests, as it does now.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9-/_]+)/?$ index.php?id=$1 [L,QSA]

htaccess redirect if URI contains string to index.php

I would like to redirect link http://example.com/asdasdas/edit to http://example.com/asdasdas/index.php/edit using htaccess. I did this:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} edit
RewriteRule ^ %{REQUEST_URI}/index.php [L,R=301]
but it's a loop and doesn't works well. Any ideas?
You can use this rule in /asdasdas/.htaccess:
RewriteEngine On
RewriteBase /asdasdas/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.+) index.php/$ [L]
This will support URL of http://example.com/asdasdas/edit

Mod Rewrite, convert subdirectory to query string?

I'm trying to convert subdirectories to a search query. So basically:
example.com/pizza
would be converted to:
example.com/?s=pizza
I have a basic knowledge of htaccess and I have done similar things before, however this time I cannot make it work. This is the problem:
This works:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ /results/?s=$1 [L,QSA]
However when I point the rewrite target to the root the user is redirected to "example.com" without the query string.
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ /?s=$1 [L,QSA]
How can I rewrite "example.com/pizza" to "example.com/?s=pizza" ?
You may try this:
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^(?:.*)?/([^/]+)/? [NC]
RewriteRule .* /?s=%1 [L]
Maps silently:
http://example.com/any/number/of/folders/parameter with or without trailing slash.
To:
http://example.com/?s=parameter
All strings are assumed to be variable.
For permanent and visible redirection, replace [L] with [R=301,L].

simple url rewriting problem

I have an existing website where i have urls like:
/application/index/fuseaction/home.uebersicht/a/44/b/45/web/xyz.htm
I now want to redirect to:
/xyz.html
what it tried is
RewriteCond %{HTTP:Host} ^(?:www\.)?mysite.coml$
RewriteCond %{REQUEST_URI} application/index\.cfm.*
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteMap docmap_301 txt: mapping301.txt
RewriteRule ^/application/index.\cfm/(.*)\.htm ${docmap_301:$1} [NC,L,NS]
If this is an inbound rule then this should work for you:
Rewrite Engine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.+)/((.+).htm) $2l [NC,R=302]
I'm assuming that the missing l from the long url in your example was intentional.

Resources