Vanity URL, slight problem
Vanity URL, slight problem
I didn't find an appropriate section so I posted it here...
Anyways, this is my .htaccess file,
[syntax=text]
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule .* - [L]
RewriteRule ^(.*)$ http://localhost/PhpStormProjects/CMS/index.php?page=$1 [NC]
[/syntax]
and this is working great for the index page when you're on a page, index.php?page=Home turns into just Home. Fine, right?
But what if I wanted to add another RewriteRule to the index page, say, index.php?articles=$1.
I tried adding a new rule just like that but then everything turns into articles. Or can you somehow "fake" a folder.
I'm using a template system so all the content goes on the index page even blog post/articles.
And currently I'm just linking each article to index.php?article=id but I'd love for it to be like http://localhost/PhpStormProjects/CMS/Articles/id without having a real articles folder, if you get what I mean.
Is that even possible?
Anyways, this is my .htaccess file,
[syntax=text]
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule .* - [L]
RewriteRule ^(.*)$ http://localhost/PhpStormProjects/CMS/index.php?page=$1 [NC]
[/syntax]
and this is working great for the index page when you're on a page, index.php?page=Home turns into just Home. Fine, right?
But what if I wanted to add another RewriteRule to the index page, say, index.php?articles=$1.
I tried adding a new rule just like that but then everything turns into articles. Or can you somehow "fake" a folder.
I'm using a template system so all the content goes on the index page even blog post/articles.
And currently I'm just linking each article to index.php?article=id but I'd love for it to be like http://localhost/PhpStormProjects/CMS/Articles/id without having a real articles folder, if you get what I mean.
Is that even possible?
Re: Vanity URL, slight problem
[syntax=text]RewriteRule ^/articles/([0-9]+)$ index.php?articles=$1[/syntax]
if it doesn't work, try removing the slash after ^
if it doesn't work, try removing the slash after ^
Re: Vanity URL, slight problem
How would I do the links then?
[syntax=xhtml]<a href="articles/$id">Blabla</a>[/syntax]
[syntax=xhtml]<a href="articles/$id">Blabla</a>[/syntax]
Re: Vanity URL, slight problem
EcazS wrote:How would I do the links then?
[syntax=xhtml]<a href="articles/$id">Blabla</a>[/syntax]
Add a / after href=" so the link won't be broken when you click on from an article.
Re: Vanity URL, slight problem
Doesn't seem to be working, I have this,
[syntax=text]
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule .* - [L]
RewriteRule ^(.*)$ http://localhost/PhpStormProjects/CMS/index.php?page=$1 [NC]
RewriteRule ^/articles/([0-9]+)$ articles.php?articles=$1
[/syntax]
and on my index page I have,
[syntax=php]
if(isset($_GET['articles'])) {
echo "Working";
}else {
echo "Not working";
}[/syntax]
and then I go to localhost/projects/cms/articles/1 but I get "Not Working"
[syntax=text]
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule .* - [L]
RewriteRule ^(.*)$ http://localhost/PhpStormProjects/CMS/index.php?page=$1 [NC]
RewriteRule ^/articles/([0-9]+)$ articles.php?articles=$1
[/syntax]
and on my index page I have,
[syntax=php]
if(isset($_GET['articles'])) {
echo "Working";
}else {
echo "Not working";
}[/syntax]
and then I go to localhost/projects/cms/articles/1 but I get "Not Working"
Re: Vanity URL, slight problem
[syntax=text]RewriteRule ^(.*)$ http://localhost/PhpStormProjects/CMS/index.php?page=$1 [NC][/syntax]
this rule, will match anything. If you swap them around so the articles one comes first, that might work.
this rule, will match anything. If you swap them around so the articles one comes first, that might work.
Re: Vanity URL, slight problem
I still get "Not Working", am I even going to the right URL- or should I change the other rule to NOT match everything, will that little PHP "script" even work properly for this? :S
Re: Vanity URL, slight problem
Try this
[syntax=text] RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^/articles/([0-9]+)$ articles.php?articles=$1 [L]
RewriteRule ^(.*)$ http://localhost/PhpStormProjects/CMS/index.php?page=$1 [NC][/syntax]
The [L] means no more rules will be processed after that one matches. I removed one rule as it looked like it should not be doing anything useful, you can obviously put it back![Wink ;)](./images/smilies/icon_e_wink.gif)
[syntax=text] RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^/articles/([0-9]+)$ articles.php?articles=$1 [L]
RewriteRule ^(.*)$ http://localhost/PhpStormProjects/CMS/index.php?page=$1 [NC][/syntax]
The [L] means no more rules will be processed after that one matches. I removed one rule as it looked like it should not be doing anything useful, you can obviously put it back
![Wink ;)](./images/smilies/icon_e_wink.gif)
Re: Vanity URL, slight problem
Now I get "500 Internal Server Error", even if I go to the index page, localhost/projects/cms/index.php ![Shocked :shock:](./images/smilies/icon_eek.gif)
Edit,
I got it to work by re-adding that other rule,
[syntax=text]
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule .* - [L]
RewriteRule ^articles/([0-9]+)$ articles.php?articles=$1 [L]
RewriteRule ^(.*)$ index.php?page=$1 [NC]
[/syntax]
![Shocked :shock:](./images/smilies/icon_eek.gif)
Edit,
I got it to work by re-adding that other rule,
[syntax=text]
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule .* - [L]
RewriteRule ^articles/([0-9]+)$ articles.php?articles=$1 [L]
RewriteRule ^(.*)$ index.php?page=$1 [NC]
[/syntax]
Re: Vanity URL, slight problem
This problem is related to this so I hope it's OK that I don't start a new topic.
I'm using that .htaccess file I posted as working and a "navigation template" that grabs URLs from the DB or rather names from the DB and then echoes the name in an anchor tag.
Problem is, if I go onto articles/2 and then click Home it'll take me to articles/Home and there is no article with the ID home so I get a pleasant visit from Mr. 404.
And on my links if I do ./name it takes me to the root, which is localhost. And I have all the files in localhost/Projects/CMS. Only for testing now then, on my live site it's going to be in the root but I wanna think ahead if I where to use it inside of a folder![Smile :)](./images/smilies/icon_e_smile.gif)
Anything on this?
I'm using that .htaccess file I posted as working and a "navigation template" that grabs URLs from the DB or rather names from the DB and then echoes the name in an anchor tag.
Problem is, if I go onto articles/2 and then click Home it'll take me to articles/Home and there is no article with the ID home so I get a pleasant visit from Mr. 404.
And on my links if I do ./name it takes me to the root, which is localhost. And I have all the files in localhost/Projects/CMS. Only for testing now then, on my live site it's going to be in the root but I wanna think ahead if I where to use it inside of a folder
![Smile :)](./images/smilies/icon_e_smile.gif)
Anything on this?
Re: Vanity URL, slight problem
What does linking to /home do ? You could also try ../home but that would break the folders above.
Re: Vanity URL, slight problem
/home does the same as ./home :S
-
- Posts: 534
- Joined: Thu May 05, 2011 8:19 pm
Re: Vanity URL, slight problem
EcazS wrote:/home does the same as ./home :S
./home is different to ../home
I don't like to brag, but I wasn't circumcised. I was circumnavigated. ![Wink ;)](./images/smilies/icon_e_wink.gif)
Want to learn something new? Or maybe reinforce what you already know? Or just help out? Please subscribe to my videos: http://goo.gl/58pN9
![Wink ;)](./images/smilies/icon_e_wink.gif)
Want to learn something new? Or maybe reinforce what you already know? Or just help out? Please subscribe to my videos: http://goo.gl/58pN9
Re: Vanity URL, slight problem
bowersbros wrote:./home is different to ../home
I know, what's your point?
-
- Posts: 534
- Joined: Thu May 05, 2011 8:19 pm
Re: Vanity URL, slight problem
Well..
/home is exactly the same as ./home
try ../home
/home is exactly the same as ./home
try ../home
I don't like to brag, but I wasn't circumcised. I was circumnavigated. ![Wink ;)](./images/smilies/icon_e_wink.gif)
Want to learn something new? Or maybe reinforce what you already know? Or just help out? Please subscribe to my videos: http://goo.gl/58pN9
![Wink ;)](./images/smilies/icon_e_wink.gif)
Want to learn something new? Or maybe reinforce what you already know? Or just help out? Please subscribe to my videos: http://goo.gl/58pN9
Re: Vanity URL, slight problem
bowersbros wrote:try ../home
If I do that and I'm not in a "subfolder" I will go down to localhost/projects when I actually want to stay in localhost/projects/cms
Re: Vanity URL, slight problem
This is probably why phpbb has you enter the folder that the system is in in the admin panel. there may be no way around it.