Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

We have our old site into core PHP and we have developed it again into Joomla 1.5 last year (because of some limitations we have to build it into 1.5). Now the problem is the URL of sites changed as we have use SEO URLS on Joomla.

In between we have use .htaccess to redirect user from old URL to new like this

Redirect /pages/oldpage.php http://www.mydomain.com/products/category/new_page.html

Is this good practice to redirect user to new URL or not?(we have used same server).

One more thing, We have used splash page on our site, and to set up it we have made some changes and because of it one of the important link is not working, and it is

http://www.mydomail.com/index.php

How can I get rid of it? I have used DirectoryIndex splash.html home.html index.php in .htaccess to open splash page first when someone open my site www.mydomain.com.

Note: my website hosted on dedicated Ubuntu server.


EDIT: As mentioned I use Joomla and I have enabled SEF facility into it and it has already written .htaccess as per below (as I do not understand it much).

DirectoryIndex splash.html home.html index.php   
 RewriteEngine On

  ########## Begin - Rewrite rules to block out some common exploits
## If you experience problems on your site block out the operations listed below
## This attempts to block the most common type of exploit `attempts` to Joomla!
#
## Deny access to extension xml files (uncomment out to activate)
#<Files ~ "\.xml$">
#Order allow,deny
#Deny from all
#Satisfy all
#</Files>
## End of deny access to extension xml files
RewriteCond %{QUERY_STRING} mosConfig_[a-zA-Z_]{1,21}(=|\%3D) [OR]
# Block out any script trying to base64_encode crap to send via URL
RewriteCond %{QUERY_STRING} base64_encode.*\(.*\) [OR]
# Block out any script that includes a <script> tag in URL
RewriteCond %{QUERY_STRING} (\<|%3C).*script.*(\>|%3E) [NC,OR]
# Block out any script trying to set a PHP GLOBALS variable via URL
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
# Block out any script trying to modify a _REQUEST variable via URL
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
# Send all blocked request to homepage with 403 Forbidden error!
RewriteRule ^(.*)$ index.php [F,L]

RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/index.php
RewriteCond %{REQUEST_URI} (/|\.php|\.html|\.htm|\.feed|\.pdf|\.raw|/[^.]*)$ [NC]
RewriteRule (.*) index.php
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]

Redirect /pages/oldpage.php http://www.mydomain.com/products/category/new_page.html
.....................
.................
share|improve this question
    
You say that index.php does not work - what happens exactly? –  w3d Oct 1 '12 at 8:38
    
It shows 404 page of joomla –  pkachhia Oct 1 '12 at 8:39
    
I am rather puzzled by this line: RewriteRule ^(.*)$ index.php [F,L] - this would appear to unconditionally rewrite all URLs to index.php and return a 403 Forbidden?! I would have expected some RewriteCond directives before this? –  w3d Oct 1 '12 at 9:04
    
Yes there are, I have edited my question for it. –  pkachhia Oct 1 '12 at 9:12
    
A silly question, but... presumably /index.php does actually exist? –  w3d Oct 1 '12 at 11:49
show 3 more comments

1 Answer 1

Is this good practice to redirect user to new URL or not?

Yes, you will need to do this if you wish to maintain your search engine ranking and prevent any old links to your site from breaking. However, you need to use a 301 (moved permanently) redirect...

Redirect 301 /pages/oldpage.php ....

If you omit the status code then a 302 (temporary) redirect will be returned and search engines might not update their links.


http://www.mydomail.com/index.php    # Returns 404 when accessed directly

(Note: The following is generic code for redirecting from /index.php to the bare URL /, if /index.php is not working (it exists but is returning a 404 when accessed directly) then there is possibly something else amiss that needs to be corrected.)

Again, you need to 301 redirect from /index.php to your domain root (presumably http://www.mydomain.com works OK?!). However, this might not be quite so straight forward if you have DirectoryIndex index.php as you could create an redirect loop as mod_dir will internally rewrite / to /index.php. However, this can resolved with mod_rewrite and specifically checking THE_REQUEST and only redirecting when it is a request from the client (HTTP) and not an internal rewrite.

Options +FollowSymLinks
DirectoryIndex index.php

RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule ^index\.php$ http://www.example.com/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

(In fact you should probably be redirecting from any directory index to the bare URL.)

share|improve this answer
    
Thanks for your reply. –  pkachhia Oct 1 '12 at 5:03
    
Thanks for your edit –  pkachhia Oct 1 '12 at 8:40
    
I would hold off using my code for the minute. If /index.php is not working then there is possibly something else amiss. Presumably if you access the domain root (http://www.mydomain.com/) then it works OK? –  w3d Oct 1 '12 at 8:59
    
yes if I access domain root it is working as I have set directory index set to splash.html page, the splash page displayed, but if I write mydomain.com/index.php then it will gives me 404 error –  pkachhia Oct 1 '12 at 9:10
    
Hi w3d, is there any suggestion for me? Please help me to get rid of this problem –  pkachhia Oct 1 '12 at 10:21
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.