How to change specific page slug with .HTACCESS? - .htaccess

I got a website script where it's very difficult to change page slugs.
So I thought I can do this with .htaccess.
I got my page url like - www.mysite.com/submit
So can I change this with .htaccess to www.mysite.com/create ???
Thank you!

Something as simple as your example can be easily done by .htaccess. Use this code in .htaccess under DOCUMENT_ROOT:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^submit/?$ create [L,NC,R]

RewriteRule ^create\$ /submit [L]
or
RewriteRule ^create$ /submit [L]

Related

Friendly url on pagination url?

I have this
http://localhost/index.php?page=1
And I want show this
http://localhost/index.php/page/1
I have now on .htaccess this code:
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^index/([0-9]+)$ index.php?page=$1
But this not work, please help me.
You are missing your script extension an page part
RewriteRule ^index.php/page/([0-9]+)$ index.php?page=$1

Need change inside htaccess file

i have following htaccess file:
Options +FollowSymLinks
RewriteEngine on
RewriteRule !^/?(maintenance\.html|.*\.css|.*\.js)$ http://www.example.com/maintenance.html [R=302,L]
RewriteRule ^([A-Za-z0-9]+)$ $1.php
RewriteRule ^home\.php$ index.php
RewriteRule ^home$ index.php
as you can see all, no matter which page you visit on the website it will be redirected to maintenance.html. I also need a small change that will exclude one more location from this. Since I am using Magento, I need to exclude admin area from this redirect so I think these are the urls that I need
http://www.example.com/index.php/admin_852_in
http://www.example.com/skin/
http://www.example.com/js/
http://www.example.com/media/
What rule should I add for these two urls too?
thanks!
You can tweak your exclusions like this:
Options +FollowSymLinks
RewriteEngine on
RewriteRule !^/?(maintenance\.html$|index\.php/admin|css/|js/|.*\.(css|js)$) http://www.example.com/maintenance.html [R=302,L,NC]

.htaccess redirect a dynamic page to an external page URL won't work

I need to redirect a few specific dynamic php pages to an external website domain. For example,
siteA.com/home/space.php?uid=357&do=thread&id=396
to
siteB.com
I put the following in my .htaccess but it didn't work.
Options +FollowSymlinks -MultiViews
RewriteEngine On
Redirect home/space.php?uid=357&do=thread&id=396 http://www.siteB.com
what's wrong with this? any suggestion is appreciated. thanks!
From this:
Redirect home/space.php?uid=357&do=thread&id=396 http://www.siteB.com
to this:
RewriteRule ^[home/space.php?uid=357&do=thread&id=396]+$ http://www.siteB.com [R=301,L]
You need to use RewriteCond for matching query string:
Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteCond %{QUERY_STRING} ^uid=357&do=thread&id=396$ [NC]
RewriteRule ^home/space\.php$ http://www.siteB.com [L,NC,R=302]

What's wrong with my .htaccess code?

I want to redirect www.example.com/ext_jobs/ to www.example.com/customer/tremoria/ext_jobs/
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^/ext_jobs/(.*)$ customer/tremoria/ext_jobs/$1 [L]
But my solution is not working. What's wrong?
You can use the rewritebase instead of the / in ^/ext_jobs/(.*)$
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_URI} !^customer/tremoria/ext_jobs
RewriteRule ^ext_jobs/(.*)/?$ customer/tremoria/ext_jobs/$1 [L,NC,QSA]
Do not use mod-rewrite for simple things. You have simple solutions with mod-alias like Redirect, RedirectMatch and Alias.
In your case I would try a Redirect if you really need a Redirect. But in your sample you are only doing an internal redirect, transparent to the user browser.
So an Alias is maybe the solution
Alias ext_jobs/ customer/tremoria/ext_jobs/

Problem with .htaccess a very peculiar case

I am using .htaccess and mod_rewrite to make URLs in my application more user friendly.
I have a page myapp.com/register.php and I use the below in .htaccess to make it work like myapp.com/register:
RewriteEngine on
Options +FollowSymLinks
RewriteBase /
RewriteRule ^register/$ register.php
It doesn't work, but when I change the code like:
RewriteEngine on
Options +FollowSymLinks
RewriteBase /
RewriteRule ^aregister/$ register.php
Then access the url myapp.com/register the page gets loaded fine.
Is this a peculiar case? Or am I doing it wrong? Please suggest.

Resources