0

I have a simple profile system in place that has a URL re-write that changes URLs like:

www.domain.com/profile.php?id=user 

To:

www.domain.com/user

Using:

RewriteEngine on
RewriteRule ^([A-Za-z0-9]+)$ profile.php?id=$1 [L]

That being said, how would I change the URL:

www.domain.com/something/index.php

To:

www.domain.com/something

Without disrupting the profile URL setup? Would I just put the rewrite higher up in the .htaccess file? Thank you for helping a rookie out.

4
  • try RewriteRule ^something something/index.php [L] Commented Apr 14, 2014 at 5:52
  • something is constant or can be anything? Commented Apr 14, 2014 at 6:05
  • well it might be www.domain.com/forums/index.php or www.domain.com/questions/index.php Commented Apr 14, 2014 at 6:12
  • @Kragalon it is not possible to do that, you need to use different url pattern for that. See my answer Commented Apr 14, 2014 at 6:14

2 Answers 2

1

If something is not constant it is not possible to do that, you need to use another url pattern like www.domain.com/page/something. However, if the `something constant, you can use;

RewriteEngine on
RewriteCond !^something [NC]
RewriteRule ^([A-Za-z0-9]+)$ profile.php?id=$1 [L]

RewriteCond ^something [NC]
RewriteRule ^something something/index.php [L] 

If you use different url pattern like ;

www.domain.com/page/something you can use;

RewriteEngine on
RewriteRule ^page/([A-Za-z0-9]+)$ $1/index.php [L]
Sign up to request clarification or add additional context in comments.

9 Comments

I think I get what you mean, but I think it is possible to do. As an example, www.twitch.tv/directory and www.twitch.tv/lassiz reference completely different php scripts, yet they have the same layout.
However, how did you know it is a directory or username? You need to check it programatically. If you know a way to determine something a user or directory I can show you the solution how to solve. As I said you above, if something is constant it is possible. Or If you have list for directories that is also possible. You need to give rewrite cond to do that
So your answer would work if I say, wanted 'something' to be 'forums' as in: www.domain.com/forums/index.php to become www.domain.com/forums ? Thank you for the help by the way.
My answer works if you say www.domain.com/page/forums/index.php, In order to make your condition work, I need a list of directory to act like a directory instead of user profile. Thi links you have gavme me probably use constant url pattern. I mean, site owner implemented a controller with url mapping /directory. When user go to this url, custom controller works. But in this url, http://www.twitch.tv/lassiz url rewrite works. In this case there is a order. First goes to controller mapping and it goes user profile, if it cannot find any matching.
It seems I have gotten what I wanted with: RewriteEngine on RewriteRule ^forums/$ forums/index.php [L] Am I being foolish?
|
0

You can use this rule to remove /index.php from any where:

DirectoryIndex index.php
RewriteEngine On

RewriteCond %{THE_REQUEST} /index\.php [NC]
RewriteRule ^(.*?)index\.php$ /$1 [L,R=301,NC,NE]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([A-Za-z0-9]+)/?$ profile.php?id=$1 [L,QSA]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.