PDA

View Full Version : mod_rewrite help +rep



Trigs
16-06-2012, 11:15 PM
Haven't used mod_rewrite in ages.

I have links that look like:
site.com/index.php?p=page-name
site.com/index.php?p=folder/page-name
site.com/index.php?p=page-name&get=arg

Please refresh my memory on how I would achieve:
site.com/page-name
site.com/folder/page-name
site.com/page-name/get/arg

Thanks!

Nath.
17-06-2012, 03:40 PM
Hi Fazon.

Are you looking for something like this?



RewriteRule ^page-name/([^/]+)(|/)$ /index.php?p=$1

That is only an example for the first one.

Trigs
17-06-2012, 05:44 PM
Yeah that's what I'm looking for!

Is there a way to make it so that it ignores the /site-name/? For example:

google.com/index.php?p=register becomes google.com/register

Thanks again.

QUOTE=Nath.;7572053]Hi Fazon.

Are you looking for something like this?



RewriteRule ^page-name/([^/]+)(|/)$ /index.php?p=$1

That is only an example for the first one.[/QUOTE]

Nath.
17-06-2012, 09:39 PM
RewriteRule ^page-name/(|/)$ /index.php?p=$1

That should work.

Trigs
18-06-2012, 12:16 AM
RewriteRule ^page-name/(|/)$ /index.php?p=$1

That should work.

Nope, doesn't seem to work.

Nath.
18-06-2012, 05:02 PM
Hi Fazon,

Can you give me an example of the URL and what the URL actually looks like? (You don't need to give me your website URL).

Trigs
18-06-2012, 06:17 PM
(Actual URLs)

Using the latest code you provided:

www.hab.net63.net/index.php?p=register (http://www.hab.net63.net/index.php?p=register) doesn't become www.hab.net63.net/register/ (http://www.hab.net63.net/register/)

When I tried the first code, that same link above became www.hab.net63.net/site-name/register (http://www.hab.net63.net/site-name/register)

Nath.
18-06-2012, 07:18 PM
RewriteEngine on
RewriteRule ^register(|/)$ index.php?p=register

It won't change the page name, but instead of redirecting a user (with a link or whatever) to www.hab.net63/index.php?p=register you can direct them to: www.hab.net63/register.

Hope I helped.

Trigs
18-06-2012, 07:24 PM
RewriteEngine on
RewriteRule ^register(|/)$ index.php?p=register

It won't change the page name, but instead of redirecting a user (with a link or whatever) to www.hab.net63/index.php?p=register (http://www.hab.net63/index.php?p=register) you can direct them to: www.hab.net63/register (http://www.hab.net63/register).

Hope I helped.

But how can I make it apply globally to all pages? If I'm not mistaken, that will only apply to index.php?p=register. What if I have register, login, logout (for example)?

Chippiewill
18-06-2012, 07:29 PM
I believe you can use a wildcard like so:


RewriteEngine On
RewriteRule ^(.*)$ index.php?title=$1 [PT,L,QSA]

Nath.
18-06-2012, 07:42 PM
Yes.

RewriteEngine on
RewriteRule (.*) index.php?p=$1 [PT,QSA]

Trigs
18-06-2012, 07:43 PM
I believe you can use a wildcard like so:


RewriteEngine On
RewriteRule ^(.*)$ index.php?title=$1 [PT,L,QSA]


RewriteRule ^(.*)$ index.php?p=$1 [PT,L,QSA]

Doesn't seem to work

Nath.
18-06-2012, 07:48 PM
RewriteRule ^(.*)$ index.php?p=$1 [PT,L,QSA]

Doesn't seem to workBoth of ours should work.

Trigs
18-06-2012, 10:03 PM
Just to confirm, it should be turning www.hab.net63.net/index.php?p=register (http://www.hab.net63.net/index.php?p=register) into www.hab.net63.net/register (http://www.hab.net63.net/register) right?

If so, it's not working. If you want to check it out, you can use the above links. The .htaccess is currently:

Options +FollowSymlinks
RewriteEngine on
RewriteRule ^(.*)$ index.php?p=$1 [PT,L,QSA]

Nath.
18-06-2012, 10:09 PM
Out of curiosity, can you add this to the top of the .htaccess file:

RewriteBase /

Trigs
18-06-2012, 10:17 PM
Out of curiosity, can you add this to the top of the .htaccess file:

RewriteBase /
That seemed to do the trick!

However the CSS isn't loading now. I tried changing the path to the .css file from lib/global.css to ./lib/global.css and ../lib/global.css but it doesn't seem to solve it.

Nath.
18-06-2012, 10:24 PM
That seemed to do the trick!

However the CSS isn't loading now. I tried changing the path to the .css file from lib/global.css to ./lib/global.css and ../lib/global.css but it doesn't seem to solve it.

The page that shows when you visit the .css file looks like a 404 if you ask me..

Can you try putting the css file in here: http://www.hab.net63.net/lib/noty/css/

Trigs
19-06-2012, 01:55 AM
The page that shows when you visit the .css file looks like a 404 if you ask me..

Can you try putting the css file in here: http://www.hab.net63.net/lib/noty/css/
I put it there, still not working

Nath.
19-06-2012, 04:04 PM
I put it there, still not working

Have you got it working yet? I see that the CSS is loading..

Trigs
19-06-2012, 04:23 PM
Have you got it working yet? I see that the CSS is loading..

Nope, wasn't working. I just cleared the htaccess file for now so I can continue to work on the site (which is why the CSS is fine now)

Nath.
19-06-2012, 04:37 PM
Nope, wasn't working. I just cleared the htaccess file for now so I can continue to work on the site (which is why the CSS is fine now)

Did you try both of our htaccess'?

Trigs
19-06-2012, 04:44 PM
Yup, tried em all

Did you try both of our htaccess'?

Want to hide these adverts? Register an account for free!