I have a URL like:
http://localhost/admin-s/index.php?m=user
However, I would like a URL like this:
http://localhost/admin-s/user
I try like this:
RewriteRule ^([a-z0-9]+).php$ index.php?nol&m=$1 [L]
RewriteCond %{QUERY_STRING} ^m=([a-zA-Z0-9]+)$
RewriteRule ^index.php$ user%1.php [L]
How to make it?
Hope this simple configuration will help you out. You can check this configuration here
This will redirect request of this pattern from http://localhost/admin-s/index.php?m=user to http://localhost/admin-s/user
Explanation:
1. If REQUEST_URI is /admin-s/index.php
2. If QUERY_STRING is m=someWords
3. Redirect to /admin-s/someWords
.htaccess
RewriteEngine on
Options -MultiViews
RewriteCond %{REQUEST_URI} \/admin\-s\/index\.php
RewriteCond %{QUERY_STRING} m=([\w]+)
RewriteRule ^(.*)$ /admin-s/%1? [R=301,L]
The question was answered here : How to turn dynamic URL into static URL
For your problem may be try following rules:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^admin-s/([^-]+) /index.php?m=$1 [R=301,QSA,L]
Let us know if it works
You can use the following rule in your root/.htaccess or /admin-s/.htaccess :
RewriteEngine on
#redirect /admin-s/index.php?m=user to /admin-s/user
RewriteCond %{THE_REQUEST} /admin-s/index\.php\?m=([^\s&]+) [NC]
RewriteRule ^ /admin-s/%1? [L,R]
#rewrite the new uri back to the orignal location
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(?:admin-s/)?(.+)$ /admin-s/index.php?m=$1 [NC,L]
Try below in your admin-s direcotry,
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([\w-]+)$ index.php?m=$1 [L]
Related
My Htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /test
RewriteCond %{THE_REQUEST} \s/index\.php\?id=([0-9]+)&title=([^\s&]+)\s [NC]
RewriteRule ^ %2-%1? [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+?)-([0-9]+)$ index.php?id=$2&title=$1 [L]
</IfModule>
I have in php urls as this :
index.php?id=34234&title=Hello_World&name=Mike
In the link i put this :
TEST
And i try get this url
http://www.test.com/34234/hello_world/mike
But all time give error as 404 error and i don´t know which it´s the solution for this, Thank´s in advanced
Your original URL has 3 path segments while your rule accepts only two. You need to fix your regex patterns
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} \s/index\.php\?id=([0-9]+)&title=([^\s&]+)&name=([^\s&]+)\s [NC]
RewriteRule ^ %1/%2/%3? [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([0-9]+)/([^/]+)/(.+)/?$ index.php.php?id=$1&title=$2&name=$3 [L]
</IfModule>
I'm struggling with a problem trying to rewrite a url without changeing its content.
I want to display in browser url a different url, but the content still the same
My url is http://fortin.agency/audit-seo/frtcrwl/health_check/report/578/leasingautomobile.ro
And i wanna change it to http://fortin.agency/audit-seo/578/leasingautomobile.ro
What i've done:
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^frtcrwl/health_check/report/(.*)$ /$1 [L,NC,R=301,NE]
Doesnt work... Any help?
EDIT
578 in the url is dynamic, also the "leasingautomobile.ro"
EDIT #2
Final code:
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/(audit-seo)/frtcrwl/health_check/report/(.+)$ [NC]
RewriteRule ^ /%1/%2 [L,R=301,NE]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php?/$0 [PT,L]
Still not working as expected yet as it throws error 404. Can the path remain unchanged? Coz the url in browser link now is perfect. Thanks to #anubhava till now
Change your rule to this and retest inside frtcrwl/.htaccess
Options +FollowSymlinks
RewriteEngine on
RewriteBase /audit-seo/frtcrwl/
RewriteCond %{THE_REQUEST} \s/+(audit-seo/frtcrwl)/health_check/report/(\S+) [NC]
RewriteRule ^ /%1/%2 [L,R=301,NE]
RewriteRule ^\d+/[^/]+/?$ index.php?/health_check/report/$0 [L,NC,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php?/$0 [PT,L,QSA]
If you want to be abble to access http://fortin.agency/audit-seo/frtcrwl/health_check/report/578/leasingautomobile.ro from http://fortin.agency/audit-seo/578/leasingautomobile.ro you can use the following rules:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^audit-seo/(.+)$ audit-seo/frtcrwl/health_check/report/$1 [L,NC]
My .htaccess looks like this..
Options -Indexes
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
RewriteCond %{HTTP_HOST} ^sub\.domain\.com$ [NC]
RewriteRule ^(.*)$ https://www.domain.com/members/invite/$1 [R,L]
</IfModule>
I want to be able to redirect an URL that looks like this..
https://sub.domain.com/ZTHF76
to...
https://www.domain.com/members/invite/ZTHF76
But instead I am getting
https://www.domain.com/members/invite/index.php
I need to keep the first rule to remove index.php from the URI of the rest of the application.
Any help with this greatly appreciated.
You should reorder your rules and keep redirect rule before rewrite one:
Options -Indexes
RewriteEngine On
RewriteCond %{HTTP_HOST} ^sub\.domain\.com$ [NC]
RewriteRule ^(.*)$ https://www.domain.com/members/invite/$1 [L,R=302]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
I have the php file page.php.
URLS:
page.php?content=contact
page.php?content=aboutus
I need it to be shown like this:
mysite.com/contact
mysite.com/aboutus
I figured out that I have to make .htaccess
RewriteEngine on
RewriteRule ^paginas/([^/]+)/?$ page.php?page=contact [L]
Tryed many things.. No results..
Thanks for attention
Try:
RewriteEngine On
RewriteCond %{THE_REQUEST} ^(?:GET|HEAD)\ /+page\.php\?content=([^&\ ]+)
RewriteRule ^ /%1? [L,R]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)$ /page.php?content=$1 [L]
This will first redirect: /page.php?content=anything to /anything then internally rewrite back requests like /anything to /page.php?content=anything.
What.htaccess code should I write to turn something like
localhost/article.php?id=something&number=something
into just
localhost/article/id
Thoughts guys?
You can use rules like this in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} \s/+article\.php\?id=([^\s&]+) [NC]
RewriteRule ^ article/%1? [R=302,L]
# internal forward from pretty URL to actual one
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^article/([^/]+)/?$ article.php?id=$1 [L,QSA,NC]