homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

Problems rewriting URL

 2:11 am on Feb 4, 2010 (gmt 0)

I'm trying to rewrite example.com/gggg-yyyyy/ to be example.com/yyyyy/, but I'm having some problems.

The text on /gggg-yyyy is saved in a database. I've set the slug in my admin area and it use this in .htaccess:

RewriteRule ^gggg-(.*)/$ gggg.php?p=$1 [QSA,L]

I'm not able to access example.com/gggg.php?p=15 (15 is the ID).

I'm not really sure how to put the question... Does anyone of you see the problem (and a solution)?



 3:08 am on Feb 4, 2010 (gmt 0)

I don't understand your question.

What is the URL? -- That is, what URL are you publishing as the link on your page?

I assume that requests for this URL are to be rewritten/mapped/forwarded to the script "gggg.php" with an id value of "yyyy", but that's all I can derive from your post.

mod_rewrite translates incoming URL requests to filepath requests, so it is critical to state both the requested URL and the required destination filepath.



 4:53 am on Feb 4, 2010 (gmt 0)

Thanks Jim,

"What is the URL?"

I'm not sure what the URL is, but I was guessing it was example.com/gggg.php?p=15 - no luck. It's actually redirecting me to the main page. .htaccess contains this:

#RewriteCond %{THE_REQUEST} /index\.php\ HTTP/
#RewriteRule ^index\.php$ / [R=301,L]

Can I somehow exclude only "/gggg.php?p=15" from this?

(The site is built on Smarty and I guess this is pretty important for the safety...)


 3:53 pm on Feb 4, 2010 (gmt 0)

What is the URL? -- What URL do you see pop up in the browser's status bar (usually at the bottom left of the browser's window) when you hover your cursor over one of these links on your Web page?

What is the server filepath of the file to be used to serve that URL? If a request arrives at your server for that URL, what file do you want to serve in response to that request?

URLs and filepaths are two entirely-different things. URLs are used only "out on the Web" and filepaths are used only "inside the server." Mod_rewrite's job is to translate requested URLs to server filepaths, and it cannot work with guesses -- You will have to be sure of your answer.



 1:34 am on Feb 5, 2010 (gmt 0)

The URL is "example.com/gggg-yyyy/" (I see that I wrote five y's in the opening post).

Filepath may be(?): /home/4/r/something/www/nameofmydomain/templates/default/gggg.tpl
while "gggg.php" is located here:

(It's a Smarty template system. .tpl is the template file.)

Sorry that I'm a complete newb at this. I really appreciate the help.


 2:15 am on Feb 5, 2010 (gmt 0)

OK, so as I understand it, the URL published on your page is example.com/gggg-yyyy/ and there is currently a rewriterule in place to rewrite requests for that URL to the filepath /gggg.php in your Web root directory, with a query string of p=yyyy.

Now what is it that you wish to change? If you wish to change the script filepath, then you must modify the RewriteRule. If you wish to change the URL, then you must modify the script(s) that generate your Web pages and the URLs linked-to on those Web pages. This is possibly gggg.php itself, though I can't be sure. Alternately, look into buying a plug-in to do this for you.



 7:43 pm on Feb 5, 2010 (gmt 0)

Ohh, now I'm really emberessed... example.com/gggg.php?p=yyyy loads the page, of course. Sorry. :|

So, the question. I would like to access example.com/gggg.php?p=yyyy from the following address: example.com/yyyy/

- How should the RewriteRule look like?



 11:50 pm on Feb 5, 2010 (gmt 0)

What have you tried so far?

Code to do something similar to that is posted almost every day in this forum.

Please check out related threads and see if you can get the basics coded up from there.


 2:44 am on Feb 6, 2010 (gmt 0)

> I would like to access [the file] example.com/gggg.php?p=yyyy from the following [URL] : example.com/yyyy/

Well, that is what your originally-posted rule should do. Disregarding the other rule you posted (which appears to have been commented-out at some point), your .htaccess file must contain all three of these lines, or the second two of these three lines -- I can't tell without inspecting your server configuration files, so you will have to test.

Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteRule ^(.+)/$ gggg.php?p=$1 [QSA,L]

This takes a request for the URL "example.com/<anything>/" and rewrites it to the script file at "/gggg.php" with a query string of "<anything>".

But read that again... You will not be able to have any subdirectories on this server, because anything and everything that ends with a slash will get rewritten to the script. Is that what you want?



 5:44 am on Feb 6, 2010 (gmt 0)

Jim: I have other subdirectories, so I guess I need a rewritecond of some sort?

I've tried a couple of things now. It feels warm, but the ice is thin...

This redirects example.com/gggg.php?=yyyy to example.com/yyyy/ but it still returns a 404:

RewriteCond %{query_STRING} ^p=yyyy$
RewriteRule ^gggg\.php$ http:// example.com/yyyy/?$1 [R=301,L]

Edit: I have to emphasize, yyyy is a specific query (like 'articlenumber833'). I'm only trying to rewrite one page. Sorry if I was vague.


 1:20 pm on Feb 6, 2010 (gmt 0)

I'm not sure why you insist on taking code that should work and modifying it so that it is backwards and cannot work.

I suggest you spend several weeks in the apache documentation, the other documents cited in our Forum Charter, and our Apache Forum Library, as I seem to be unable to clarify this process any further for you as things now stand...



 4:18 am on Feb 8, 2010 (gmt 0)

Yes, I guess it is about time I actually learn this properly. I will do that. Thanks for trying and being patient with me. :)

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved